abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
vecHash.h
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [vecHash.h]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Resizable arrays.]
8 
9  Synopsis [Hashing integer pairs/triples into an integer.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: vecHash.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #ifndef ABC__misc__vec__vecHash_h
22 #define ABC__misc__vec__vecHash_h
23 
24 
25 ////////////////////////////////////////////////////////////////////////
26 /// INCLUDES ///
27 ////////////////////////////////////////////////////////////////////////
28 
29 #include <stdio.h>
30 
32 
33 
34 ////////////////////////////////////////////////////////////////////////
35 /// PARAMETERS ///
36 ////////////////////////////////////////////////////////////////////////
37 
38 ////////////////////////////////////////////////////////////////////////
39 /// BASIC TYPES ///
40 ////////////////////////////////////////////////////////////////////////
41 
44 {
45  int iData0;
46  int iData1;
47  int iData2;
48  int iNext;
49 };
50 
53 {
54  Vec_Int_t * vTable; // hash table
55  Vec_Int_t * vObjs; // hash objects
56 };
57 
58 ////////////////////////////////////////////////////////////////////////
59 /// MACRO DEFINITIONS ///
60 ////////////////////////////////////////////////////////////////////////
61 
62 static inline Hash_IntObj_t * Hash_IntObj( Hash_IntMan_t * p, int i ) { return i ? (Hash_IntObj_t *)Vec_IntEntryP(p->vObjs, 4*i) : NULL; }
63 static inline int Hash_IntObjData0( Hash_IntMan_t * p, int i ) { return Hash_IntObj(p, i)->iData0; }
64 static inline int Hash_IntObjData1( Hash_IntMan_t * p, int i ) { return Hash_IntObj(p, i)->iData1; }
65 static inline int Hash_IntObjData2( Hash_IntMan_t * p, int i ) { return Hash_IntObj(p, i)->iData2; }
66 
67 static inline int Hash_Int2ObjInc( Hash_IntMan_t * p, int i ) { return Hash_IntObj(p, i)->iData2++; }
68 static inline int Hash_Int2ObjDec( Hash_IntMan_t * p, int i ) { return --Hash_IntObj(p, i)->iData2; }
69 static inline void Hash_Int2ObjSetData2( Hash_IntMan_t * p, int i, int d ) { Hash_IntObj(p, i)->iData2 = d; }
70 
71 ////////////////////////////////////////////////////////////////////////
72 /// FUNCTION DEFINITIONS ///
73 ////////////////////////////////////////////////////////////////////////
74 
75 /**Function*************************************************************
76 
77  Synopsis [Hashing data entries composed of nSize integers.]
78 
79  Description []
80 
81  SideEffects []
82 
83  SeeAlso []
84 
85 ***********************************************************************/
86 static inline Hash_IntMan_t * Hash_IntManStart( int nSize )
87 {
88  Hash_IntMan_t * p; nSize += 100;
89  p = ABC_CALLOC( Hash_IntMan_t, 1 );
90  p->vTable = Vec_IntStart( Abc_PrimeCudd(nSize) );
91  p->vObjs = Vec_IntAlloc( 4*nSize );
92  Vec_IntFill( p->vObjs, 4, 0 );
93  return p;
94 }
95 static inline void Hash_IntManStop( Hash_IntMan_t * p )
96 {
97  Vec_IntFree( p->vObjs );
98  Vec_IntFree( p->vTable );
99  ABC_FREE( p );
100 }
101 static inline int Hash_IntManEntryNum( Hash_IntMan_t * p )
102 {
103  return Vec_IntSize(p->vObjs)/4 - 1;
104 }
105 static inline void Hash_IntManProfile( Hash_IntMan_t * p )
106 {
107  Hash_IntObj_t * pObj;
108  int i, Count, Entry;
109  Vec_IntForEachEntry( p->vTable, Entry, i )
110  {
111  Count = 0;
112  for ( pObj = Hash_IntObj( p, Entry ); pObj; pObj = Hash_IntObj( p, pObj->iNext ) )
113  Count++;
114  printf( "%d ", Count );
115  }
116  printf( "\n" );
117 }
118 
119 /**Function*************************************************************
120 
121  Synopsis []
122 
123  Description []
124 
125  SideEffects []
126 
127  SeeAlso []
128 
129 ***********************************************************************/
130 static inline int Hash_Int2ManHash( int iData0, int iData1, int nTableSize )
131 {
132  return (4177 * (unsigned)iData0 + 7873 * (unsigned)iData1) % (unsigned)nTableSize;
133 }
134 static inline int * Hash_Int2ManLookup( Hash_IntMan_t * p, int iData0, int iData1 )
135 {
136  Hash_IntObj_t * pObj;
137  int * pPlace = Vec_IntEntryP( p->vTable, Hash_Int2ManHash(iData0, iData1, Vec_IntSize(p->vTable)) );
138  for ( ; (pObj = Hash_IntObj(p, *pPlace)); pPlace = &pObj->iNext )
139  if ( pObj->iData0 == iData0 && pObj->iData1 == iData1 )
140  return pPlace;
141  assert( *pPlace == 0 );
142  return pPlace;
143 }
144 static inline int Hash_Int2ManInsert( Hash_IntMan_t * p, int iData0, int iData1, int iData2 )
145 {
146  Hash_IntObj_t * pObj;
147  int i, nObjs, * pPlace;
148  nObjs = Vec_IntSize(p->vObjs)/4;
149  if ( nObjs > Vec_IntSize(p->vTable) )
150  {
151 // printf( "Resizing...\n" );
153  for ( i = 1; i < nObjs; i++ )
154  {
155  pObj = Hash_IntObj( p, i );
156  pObj->iNext = 0;
157  pPlace = Hash_Int2ManLookup( p, pObj->iData0, pObj->iData1 );
158  assert( *pPlace == 0 );
159  *pPlace = i;
160  }
161  }
162  pPlace = Hash_Int2ManLookup( p, iData0, iData1 );
163  if ( *pPlace )
164  return *pPlace;
165  *pPlace = nObjs;
166  Vec_IntPush( p->vObjs, iData0 );
167  Vec_IntPush( p->vObjs, iData1 );
168  Vec_IntPush( p->vObjs, iData2 );
169  Vec_IntPush( p->vObjs, 0 );
170  return nObjs;
171 }
172 
173 /**Function*************************************************************
174 
175  Synopsis []
176 
177  Description []
178 
179  SideEffects []
180 
181  SeeAlso []
182 
183 ***********************************************************************/
184 static inline int Hsh_Int3ManHash( int iData0, int iData1, int iData2, int nTableSize )
185 {
186  return (4177 * (unsigned)iData0 + 7873 * (unsigned)iData1 + 1699 * (unsigned)iData2) % (unsigned)nTableSize;
187 }
188 static inline int * Hsh_Int3ManLookup( Hash_IntMan_t * p, int iData0, int iData1, int iData2 )
189 {
190  Hash_IntObj_t * pObj;
191  int * pPlace = Vec_IntEntryP( p->vTable, Hsh_Int3ManHash(iData0, iData1, iData2, Vec_IntSize(p->vTable)) );
192  for ( ; (pObj = Hash_IntObj(p, *pPlace)); pPlace = &pObj->iNext )
193  if ( pObj->iData0 == iData0 && pObj->iData1 == iData1 && pObj->iData2 == iData2 )
194  return pPlace;
195  assert( *pPlace == 0 );
196  return pPlace;
197 }
198 static inline int Hsh_Int3ManInsert( Hash_IntMan_t * p, int iData0, int iData1, int iData2 )
199 {
200  Hash_IntObj_t * pObj;
201  int i, nObjs, * pPlace;
202  nObjs = Vec_IntSize(p->vObjs)/4;
203  if ( nObjs > Vec_IntSize(p->vTable) )
204  {
205 // printf( "Resizing...\n" );
207  for ( i = 1; i < nObjs; i++ )
208  {
209  pObj = Hash_IntObj( p, i );
210  pObj->iNext = 0;
211  pPlace = Hsh_Int3ManLookup( p, pObj->iData0, pObj->iData1, pObj->iData2 );
212  assert( *pPlace == 0 );
213  *pPlace = i;
214  }
215  }
216  pPlace = Hsh_Int3ManLookup( p, iData0, iData1, iData2 );
217  if ( *pPlace )
218  return *pPlace;
219  *pPlace = nObjs;
220  Vec_IntPush( p->vObjs, iData0 );
221  Vec_IntPush( p->vObjs, iData1 );
222  Vec_IntPush( p->vObjs, iData2 );
223  Vec_IntPush( p->vObjs, 0 );
224  return nObjs;
225 }
226 
227 /**Function*************************************************************
228 
229  Synopsis [Test procedure.]
230 
231  Description []
232 
233  SideEffects []
234 
235  SeeAlso []
236 
237 ***********************************************************************/
238 static inline void Hash_IntManHashArrayTest()
239 {
240  Hash_IntMan_t * p;
241  int RetValue;
242 
243  p = Hash_IntManStart( 10 );
244 
245  RetValue = Hash_Int2ManInsert( p, 10, 11, 12 );
246  assert( RetValue );
247 
248  RetValue = Hash_Int2ManInsert( p, 20, 21, 22 );
249  assert( RetValue );
250 
251  RetValue = Hash_Int2ManInsert( p, 10, 11, 12 );
252  assert( !RetValue );
253 
254  Hash_IntManStop( p );
255 }
256 
257 
258 
259 ////////////////////////////////////////////////////////////////////////
260 /// END OF FILE ///
261 ////////////////////////////////////////////////////////////////////////
262 
264 
265 #endif
266 
static Hash_IntMan_t * Hash_IntManStart(int nSize)
FUNCTION DEFINITIONS ///.
Definition: vecHash.h:86
static int Hash_Int2ObjDec(Hash_IntMan_t *p, int i)
Definition: vecHash.h:68
static int Hash_IntManEntryNum(Hash_IntMan_t *p)
Definition: vecHash.h:101
static int Abc_PrimeCudd(unsigned int p)
Definition: abc_global.h:383
static int Hash_Int2ObjInc(Hash_IntMan_t *p, int i)
Definition: vecHash.h:67
static int Hsh_Int3ManHash(int iData0, int iData1, int iData2, int nTableSize)
Definition: vecHash.h:184
static int * Hsh_Int3ManLookup(Hash_IntMan_t *p, int iData0, int iData1, int iData2)
Definition: vecHash.h:188
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static int Hash_Int2ManHash(int iData0, int iData1, int nTableSize)
Definition: vecHash.h:130
static void Hash_IntManHashArrayTest()
Definition: vecHash.h:238
static int Hash_IntObjData2(Hash_IntMan_t *p, int i)
Definition: vecHash.h:65
Vec_Int_t * vObjs
Definition: vecHash.h:55
static Vec_Int_t * Vec_IntStart(int nSize)
Definition: bblif.c:172
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
static void Hash_IntManStop(Hash_IntMan_t *p)
Definition: vecHash.h:95
static void Vec_IntFill(Vec_Int_t *p, int nSize, int Fill)
Definition: bblif.c:356
static void Hash_Int2ObjSetData2(Hash_IntMan_t *p, int i, int d)
Definition: vecHash.h:69
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
Definition: abc_global.h:105
static int * Hash_Int2ManLookup(Hash_IntMan_t *p, int iData0, int iData1)
Definition: vecHash.h:134
#define ABC_NAMESPACE_HEADER_END
Definition: abc_global.h:106
static int Hash_Int2ManInsert(Hash_IntMan_t *p, int iData0, int iData1, int iData2)
Definition: vecHash.h:144
static int Hsh_Int3ManInsert(Hash_IntMan_t *p, int iData0, int iData1, int iData2)
Definition: vecHash.h:198
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
static void Hash_IntManProfile(Hash_IntMan_t *p)
Definition: vecHash.h:105
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
typedefABC_NAMESPACE_HEADER_START struct Hash_IntObj_t_ Hash_IntObj_t
INCLUDES ///.
Definition: vecHash.h:42
static Hash_IntObj_t * Hash_IntObj(Hash_IntMan_t *p, int i)
MACRO DEFINITIONS ///.
Definition: vecHash.h:62
#define assert(ex)
Definition: util_old.h:213
static int * Vec_IntEntryP(Vec_Int_t *p, int i)
Definition: vecInt.h:417
Vec_Int_t * vTable
Definition: vecHash.h:54
static int Hash_IntObjData1(Hash_IntMan_t *p, int i)
Definition: vecHash.h:64
static int Hash_IntObjData0(Hash_IntMan_t *p, int i)
Definition: vecHash.h:63
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecInt.h:54