ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
vecHash.h
Go to the documentation of this file.
1
20
21#ifndef ABC__misc__vec__vecHash_h
22#define ABC__misc__vec__vecHash_h
23
24
28
29#include <stdio.h>
30
32
33
37
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 int nRefs; // reference counter for the manager
57};
58
62
63static inline Hash_IntObj_t * Hash_IntObj( Hash_IntMan_t * p, int i ) { return i ? (Hash_IntObj_t *)Vec_IntEntryP(p->vObjs, 4*i) : NULL; }
64static inline int Hash_IntObjData0( Hash_IntMan_t * p, int i ) { return Hash_IntObj(p, i)->iData0; }
65static inline int Hash_IntObjData1( Hash_IntMan_t * p, int i ) { return Hash_IntObj(p, i)->iData1; }
66static inline int Hash_IntObjData2( Hash_IntMan_t * p, int i ) { return Hash_IntObj(p, i)->iData2; }
67
68static inline int Hash_Int2ObjInc( Hash_IntMan_t * p, int i ) { return Hash_IntObj(p, i)->iData2++; }
69static inline int Hash_Int2ObjDec( Hash_IntMan_t * p, int i ) { return --Hash_IntObj(p, i)->iData2; }
70static inline void Hash_Int2ObjSetData2( Hash_IntMan_t * p, int i, int d ) { Hash_IntObj(p, i)->iData2 = d; }
71
75
87static inline Hash_IntMan_t * Hash_IntManStart( int nSize )
88{
89 Hash_IntMan_t * p; nSize += 100;
91 p->vTable = Vec_IntStart( Abc_PrimeCudd(nSize) );
92 p->vObjs = Vec_IntAlloc( 4*nSize );
93 Vec_IntFill( p->vObjs, 4, 0 );
94 p->nRefs = 1;
95 return p;
96}
97static inline void Hash_IntManStop( Hash_IntMan_t * p )
98{
99 Vec_IntFree( p->vObjs );
100 Vec_IntFree( p->vTable );
101 ABC_FREE( p );
102}
103static inline Hash_IntMan_t * Hash_IntManRef( Hash_IntMan_t * p )
104{
105 p->nRefs++;
106 return p;
107}
108static inline void Hash_IntManDeref( Hash_IntMan_t * p )
109{
110 if ( p == NULL )
111 return;
112 if ( --p->nRefs == 0 )
113 Hash_IntManStop( p );
114}
115static inline int Hash_IntManEntryNum( Hash_IntMan_t * p )
116{
117 return Vec_IntSize(p->vObjs)/4 - 1;
118}
119static inline void Hash_IntManProfile( Hash_IntMan_t * p )
120{
121 Hash_IntObj_t * pObj;
122 int i, Count, Entry;
123 Vec_IntForEachEntry( p->vTable, Entry, i )
124 {
125 Count = 0;
126 for ( pObj = Hash_IntObj( p, Entry ); pObj; pObj = Hash_IntObj( p, pObj->iNext ) )
127 Count++;
128 printf( "%d ", Count );
129 }
130 printf( "\n" );
131}
132
144static inline int Hash_Int2ManHash( int iData0, int iData1, int nTableSize )
145{
146 return (4177 * (unsigned)iData0 + 7873 * (unsigned)iData1) % (unsigned)nTableSize;
147}
148static inline int * Hash_Int2ManLookup( Hash_IntMan_t * p, int iData0, int iData1 )
149{
150 Hash_IntObj_t * pObj;
151 int * pPlace = Vec_IntEntryP( p->vTable, Hash_Int2ManHash(iData0, iData1, Vec_IntSize(p->vTable)) );
152 for ( ; (pObj = Hash_IntObj(p, *pPlace)); pPlace = &pObj->iNext )
153 if ( pObj->iData0 == iData0 && pObj->iData1 == iData1 )
154 return pPlace;
155 assert( *pPlace == 0 );
156 return pPlace;
157}
158static inline int Hash_Int2ManInsert( Hash_IntMan_t * p, int iData0, int iData1, int iData2 )
159{
160 Hash_IntObj_t * pObj;
161 int i, nObjs, * pPlace;
162 nObjs = Vec_IntSize(p->vObjs)/4;
163 if ( nObjs > Vec_IntSize(p->vTable) )
164 {
165// printf( "Resizing...\n" );
166 Vec_IntFill( p->vTable, Abc_PrimeCudd(2*Vec_IntSize(p->vTable)), 0 );
167 for ( i = 1; i < nObjs; i++ )
168 {
169 pObj = Hash_IntObj( p, i );
170 pObj->iNext = 0;
171 pPlace = Hash_Int2ManLookup( p, pObj->iData0, pObj->iData1 );
172 assert( *pPlace == 0 );
173 *pPlace = i;
174 }
175 }
176 pPlace = Hash_Int2ManLookup( p, iData0, iData1 );
177 if ( *pPlace )
178 return *pPlace;
179 *pPlace = nObjs;
180 Vec_IntPush( p->vObjs, iData0 );
181 Vec_IntPush( p->vObjs, iData1 );
182 Vec_IntPush( p->vObjs, iData2 );
183 Vec_IntPush( p->vObjs, 0 );
184 return nObjs;
185}
186
198static inline int Hsh_Int3ManHash( int iData0, int iData1, int iData2, int nTableSize )
199{
200 return (4177 * (unsigned)iData0 + 7873 * (unsigned)iData1 + 1699 * (unsigned)iData2) % (unsigned)nTableSize;
201}
202static inline int * Hsh_Int3ManLookup( Hash_IntMan_t * p, int iData0, int iData1, int iData2 )
203{
204 Hash_IntObj_t * pObj;
205 int * pPlace = Vec_IntEntryP( p->vTable, Hsh_Int3ManHash(iData0, iData1, iData2, Vec_IntSize(p->vTable)) );
206 for ( ; (pObj = Hash_IntObj(p, *pPlace)); pPlace = &pObj->iNext )
207 if ( pObj->iData0 == iData0 && pObj->iData1 == iData1 && pObj->iData2 == iData2 )
208 return pPlace;
209 assert( *pPlace == 0 );
210 return pPlace;
211}
212static inline int Hsh_Int3ManInsert( Hash_IntMan_t * p, int iData0, int iData1, int iData2 )
213{
214 Hash_IntObj_t * pObj;
215 int i, nObjs, * pPlace;
216 nObjs = Vec_IntSize(p->vObjs)/4;
217 if ( nObjs > Vec_IntSize(p->vTable) )
218 {
219// printf( "Resizing...\n" );
220 Vec_IntFill( p->vTable, Abc_PrimeCudd(2*Vec_IntSize(p->vTable)), 0 );
221 for ( i = 1; i < nObjs; i++ )
222 {
223 pObj = Hash_IntObj( p, i );
224 pObj->iNext = 0;
225 pPlace = Hsh_Int3ManLookup( p, pObj->iData0, pObj->iData1, pObj->iData2 );
226 assert( *pPlace == 0 );
227 *pPlace = i;
228 }
229 }
230 pPlace = Hsh_Int3ManLookup( p, iData0, iData1, iData2 );
231 if ( *pPlace )
232 return *pPlace;
233 *pPlace = nObjs;
234 Vec_IntPush( p->vObjs, iData0 );
235 Vec_IntPush( p->vObjs, iData1 );
236 Vec_IntPush( p->vObjs, iData2 );
237 Vec_IntPush( p->vObjs, 0 );
238 return nObjs;
239}
240
252static inline void Hash_IntManHashArrayTest()
253{
255 int RetValue;
256
257 p = Hash_IntManStart( 10 );
258
259 RetValue = Hash_Int2ManInsert( p, 10, 11, 12 );
260 assert( RetValue );
261
262 RetValue = Hash_Int2ManInsert( p, 20, 21, 22 );
263 assert( RetValue );
264
265 RetValue = Hash_Int2ManInsert( p, 10, 11, 12 );
266 assert( !RetValue );
267
268 Hash_IntManStop( p );
269}
270
271
272
276
278
279#endif
280
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_HEADER_END
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
Cube * p
Definition exorList.c:222
Vec_Int_t * vObjs
Definition vecHash.h:55
Vec_Int_t * vTable
Definition vecHash.h:54
#define assert(ex)
Definition util_old.h:213
typedefABC_NAMESPACE_HEADER_START struct Hash_IntObj_t_ Hash_IntObj_t
INCLUDES ///.
Definition vecHash.h:42
struct Hash_IntMan_t_ Hash_IntMan_t
Definition vecHash.h:51
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54