1 /**CFile****************************************************************
2 
3   FileName    [vecHsh.h]
4 
5   SystemName  [ABC: Logic synthesis and verification system.]
6 
7   PackageName [Resizable arrays.]
8 
9   Synopsis    [Hashing vector entries.]
10 
11   Author      [Alan Mishchenko]
12 
13   Affiliation [UC Berkeley]
14 
15   Date        [Ver. 1.0. Started - June 20, 2005.]
16 
17   Revision    [$Id: vecHsh.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #ifndef ABC__misc__vec__vecHsh_h
22 #define ABC__misc__vec__vecHsh_h
23 
24 
25 ////////////////////////////////////////////////////////////////////////
26 ///                          INCLUDES                                ///
27 ////////////////////////////////////////////////////////////////////////
28 
29 #include <stdio.h>
30 
31 ABC_NAMESPACE_HEADER_START
32 
33 
34 ////////////////////////////////////////////////////////////////////////
35 ///                         PARAMETERS                               ///
36 ////////////////////////////////////////////////////////////////////////
37 
38 ////////////////////////////////////////////////////////////////////////
39 ///                         BASIC TYPES                              ///
40 ////////////////////////////////////////////////////////////////////////
41 
42 typedef struct Hsh_Int1Man_t_ Hsh_Int1Man_t;
43 struct Hsh_Int1Man_t_
44 {
45     Vec_Int_t *  vData;       // stored data
46     Vec_Int_t *  vNext;       // next items
47     Vec_Int_t *  vTable;      // hash table
48 };
49 
50 
51 
52 typedef struct Hsh_IntObj_t_ Hsh_IntObj_t;
53 struct Hsh_IntObj_t_
54 {
55     int          iData;
56     int          iNext;
57 };
58 
59 typedef union Hsh_IntObjWord_t_ Hsh_IntObjWord_t;
60 union Hsh_IntObjWord_t_
61 {
62     Hsh_IntObj_t wObj;
63     word         wWord;
64 };
65 
66 typedef struct Hsh_IntMan_t_ Hsh_IntMan_t;
67 struct Hsh_IntMan_t_
68 {
69     int          nSize;       // data size
70     Vec_Int_t *  vData;       // data storage
71     Vec_Int_t *  vTable;      // hash table
72     Vec_Wrd_t *  vObjs;       // hash objects
73 };
74 
75 
76 
77 typedef struct Hsh_VecObj_t_ Hsh_VecObj_t;
78 struct Hsh_VecObj_t_
79 {
80     int          nSize;
81     int          iNext;
82     int          pArray[0];
83 };
84 
85 typedef struct Hsh_VecMan_t_ Hsh_VecMan_t;
86 struct Hsh_VecMan_t_
87 {
88     Vec_Int_t *  vTable;      // hash table
89     Vec_Int_t *  vData;       // data storage
90     Vec_Int_t *  vMap;        // mapping entries into data;
91     Vec_Int_t    vTemp;       // temporary array
92     Vec_Int_t    vTemp1;      // temporary array
93     Vec_Int_t    vTemp2;      // temporary array
94 };
95 
96 ////////////////////////////////////////////////////////////////////////
97 ///                      MACRO DEFINITIONS                           ///
98 ////////////////////////////////////////////////////////////////////////
99 
Hsh_IntData(Hsh_IntMan_t * p,int iData)100 static inline unsigned *      Hsh_IntData( Hsh_IntMan_t * p, int iData )  { return (unsigned *)Vec_IntEntryP( p->vData, p->nSize * iData );             }
Hsh_IntObj(Hsh_IntMan_t * p,int iObj)101 static inline Hsh_IntObj_t *  Hsh_IntObj( Hsh_IntMan_t * p, int iObj )    { return iObj == -1 ? NULL : (Hsh_IntObj_t *)Vec_WrdEntryP( p->vObjs, iObj ); }
Hsh_IntWord(int iData,int iNext)102 static inline word            Hsh_IntWord( int iData, int iNext )         { Hsh_IntObjWord_t Obj = { {iData, iNext} }; return Obj.wWord;                }
103 
Hsh_VecObj(Hsh_VecMan_t * p,int i)104 static inline Hsh_VecObj_t *  Hsh_VecObj( Hsh_VecMan_t * p, int i )  { return i == -1 ? NULL : (Hsh_VecObj_t *)Vec_IntEntryP(p->vData, Vec_IntEntry(p->vMap, i));  }
105 
106 ////////////////////////////////////////////////////////////////////////
107 ///                     FUNCTION DEFINITIONS                         ///
108 ////////////////////////////////////////////////////////////////////////
109 
110 /**Function*************************************************************
111 
112   Synopsis    [Hashing data entries composed of nSize integers.]
113 
114   Description []
115 
116   SideEffects []
117 
118   SeeAlso     []
119 
120 ***********************************************************************/
Hsh_Int1ManStart(int nEntries)121 static inline Hsh_Int1Man_t * Hsh_Int1ManStart( int nEntries )
122 {
123     Hsh_Int1Man_t * p;
124     p = ABC_CALLOC( Hsh_Int1Man_t, 1 );
125     p->vData  = Vec_IntAlloc( nEntries );
126     p->vNext  = Vec_IntAlloc( nEntries );
127     p->vTable = Vec_IntStartFull( Abc_PrimeCudd(nEntries) );
128     return p;
129 }
Hsh_Int1ManStop(Hsh_Int1Man_t * p)130 static inline void Hsh_Int1ManStop( Hsh_Int1Man_t * p )
131 {
132     Vec_IntFree( p->vData );
133     Vec_IntFree( p->vNext );
134     Vec_IntFree( p->vTable );
135     ABC_FREE( p );
136 }
Hsh_Int1ManEntryNum(Hsh_Int1Man_t * p)137 static inline int Hsh_Int1ManEntryNum( Hsh_Int1Man_t * p )
138 {
139     return Vec_IntSize(p->vData);
140 }
141 
142 
143 /**Function*************************************************************
144 
145   Synopsis    [Hashing individual integers.]
146 
147   Description []
148 
149   SideEffects []
150 
151   SeeAlso     []
152 
153 ***********************************************************************/
154 // https://en.wikipedia.org/wiki/Jenkins_hash_function
Hsh_Int1ManHash(int Data,int nTableSize)155 static inline int Hsh_Int1ManHash( int Data, int nTableSize )
156 {
157     unsigned i, hash = 0;
158     unsigned char * pDataC = (unsigned char *)&Data;
159     for ( i = 0; i < 4; i++ )
160     {
161         hash += pDataC[i];
162         hash += hash << 10;
163         hash ^= hash >> 6;
164     }
165     hash += hash << 3;
166     hash ^= hash >> 11;
167     hash += hash << 15;
168     return (int)(hash % nTableSize);
169 }
Hsh_Int1ManLookupInt(Hsh_Int1Man_t * p,int Data)170 static inline int * Hsh_Int1ManLookupInt( Hsh_Int1Man_t * p, int Data )
171 {
172     int Item, * pPlace = Vec_IntEntryP( p->vTable, Hsh_Int1ManHash(Data, Vec_IntSize(p->vTable)) );
173     for ( Item = *pPlace; Item >= 0; Item = Vec_IntEntry(p->vNext, Item) )
174         if ( Vec_IntEntry(p->vData, Item) == (int)Data )
175             return pPlace;
176     assert( Item == -1 );
177     return pPlace;
178 }
Hsh_Int1ManLookup(Hsh_Int1Man_t * p,int Data)179 static inline int Hsh_Int1ManLookup( Hsh_Int1Man_t * p, int Data )
180 {
181     return *Hsh_Int1ManLookupInt(p, Data);
182 }
Hsh_Int1ManAdd(Hsh_Int1Man_t * p,int Data)183 static inline int Hsh_Int1ManAdd( Hsh_Int1Man_t * p, int Data )
184 {
185     int i, Entry, * pPlace;
186     if ( Vec_IntSize(p->vData) > Vec_IntSize(p->vTable) )
187     {
188         Vec_IntFill( p->vTable, Abc_PrimeCudd(2*Vec_IntSize(p->vTable)), -1 );
189         Vec_IntForEachEntry( p->vData, Entry, i )
190         {
191             pPlace = Vec_IntEntryP( p->vTable, Hsh_Int1ManHash(Entry, Vec_IntSize(p->vTable)) );
192             Vec_IntWriteEntry( p->vNext, i, *pPlace ); *pPlace = i;
193         }
194     }
195     pPlace = Hsh_Int1ManLookupInt( p, Data );
196     if ( *pPlace == -1 )
197     {
198         *pPlace = Vec_IntSize(p->vData);
199         Vec_IntPush( p->vData, Data );
200         Vec_IntPush( p->vNext, -1 );
201     }
202     return *pPlace;
203 }
204 
205 /**Function*************************************************************
206 
207   Synopsis    [Test procedure.]
208 
209   Description []
210 
211   SideEffects []
212 
213   SeeAlso     []
214 
215 ***********************************************************************/
Hsh_Int1ManHashArrayTest()216 static inline void Hsh_Int1ManHashArrayTest()
217 {
218     Hsh_Int1Man_t * p = Hsh_Int1ManStart( 10 );
219 
220     printf( "Entry = %d.   Hashed = %d.\n", 5, Hsh_Int1ManAdd(p, 5 ) );
221     printf( "Entry = %d.   Hashed = %d.\n", 7, Hsh_Int1ManAdd(p, 7 ) );
222     printf( "Entry = %d.   Hashed = %d.\n", 7, Hsh_Int1ManAdd(p, 7 ) );
223     printf( "Entry = %d.   Hashed = %d.\n", 7, Hsh_Int1ManAdd(p, 7 ) );
224     printf( "Entry = %d.   Hashed = %d.\n", 8, Hsh_Int1ManAdd(p, 8 ) );
225     printf( "Entry = %d.   Hashed = %d.\n", 5, Hsh_Int1ManAdd(p, 5 ) );
226     printf( "Entry = %d.   Hashed = %d.\n", 3, Hsh_Int1ManAdd(p, 3 ) );
227     printf( "Entry = %d.   Hashed = %d.\n", 4, Hsh_Int1ManAdd(p, 4 ) );
228 
229     printf( "Size = %d.\n", Hsh_Int1ManEntryNum(p) );
230 
231     Hsh_Int1ManStop( p );
232 }
233 
234 
235 /**Function*************************************************************
236 
237   Synopsis    [Hashing data entries composed of nSize integers.]
238 
239   Description []
240 
241   SideEffects []
242 
243   SeeAlso     []
244 
245 ***********************************************************************/
Hsh_IntManStart(Vec_Int_t * vData,int nSize,int nEntries)246 static inline Hsh_IntMan_t * Hsh_IntManStart( Vec_Int_t * vData, int nSize, int nEntries )
247 {
248     Hsh_IntMan_t * p;
249     p = ABC_CALLOC( Hsh_IntMan_t, 1 );
250     p->nSize  = nSize;
251     p->vData  = vData;
252     p->vTable = Vec_IntStartFull( Abc_PrimeCudd(nEntries) );
253     p->vObjs  = Vec_WrdAlloc( nEntries );
254     return p;
255 }
Hsh_IntManStop(Hsh_IntMan_t * p)256 static inline void Hsh_IntManStop( Hsh_IntMan_t * p )
257 {
258     Vec_IntFree( p->vTable );
259     Vec_WrdFree( p->vObjs );
260     ABC_FREE( p );
261 }
Hsh_IntManEntryNum(Hsh_IntMan_t * p)262 static inline int Hsh_IntManEntryNum( Hsh_IntMan_t * p )
263 {
264     return Vec_WrdSize(p->vObjs);
265 }
266 
267 /**Function*************************************************************
268 
269   Synopsis    []
270 
271   Description []
272 
273   SideEffects []
274 
275   SeeAlso     []
276 
277 ***********************************************************************/
278 // https://en.wikipedia.org/wiki/Jenkins_hash_function
Hsh_IntManHash(unsigned * pData,int nSize,int nTableSize)279 static inline int Hsh_IntManHash( unsigned * pData, int nSize, int nTableSize )
280 {
281     int i = 0; unsigned hash = 0;
282     unsigned char * pDataC = (unsigned char *)pData;
283     nSize <<= 2;
284     while ( i != nSize )
285     {
286         hash += pDataC[i++];
287         hash += hash << 10;
288         hash ^= hash >> 6;
289     }
290     hash += hash << 3;
291     hash ^= hash >> 11;
292     hash += hash << 15;
293     return (int)(hash % nTableSize);
294 }
Hsh_IntManHash2(unsigned * pData,int nSize,int nTableSize)295 static inline int Hsh_IntManHash2( unsigned * pData, int nSize, int nTableSize )
296 {
297     static int s_Primes[7] = { 4177, 5147, 5647, 6343, 7103, 7873, 8147 };
298     unsigned char * pDataC = (unsigned char *)pData;
299     int c, nChars = nSize * 4;
300     unsigned Key = 0;
301     for ( c = 0; c < nChars; c++ )
302         Key += pDataC[c] * s_Primes[c % 7];
303     return (int)(Key % nTableSize);
304 }
Hsh_IntManLookup(Hsh_IntMan_t * p,unsigned * pData)305 static inline int * Hsh_IntManLookup( Hsh_IntMan_t * p, unsigned * pData )
306 {
307     Hsh_IntObj_t * pObj;
308     int * pPlace = Vec_IntEntryP( p->vTable, Hsh_IntManHash(pData, p->nSize, Vec_IntSize(p->vTable)) );
309     for ( ; (pObj = Hsh_IntObj(p, *pPlace)); pPlace = &pObj->iNext )
310         if ( !memcmp( pData, Hsh_IntData(p, pObj->iData), sizeof(int) * (size_t)p->nSize ) )
311             return pPlace;
312     assert( *pPlace == -1 );
313     return pPlace;
314 }
Hsh_IntManAdd(Hsh_IntMan_t * p,int iData)315 static inline int Hsh_IntManAdd( Hsh_IntMan_t * p, int iData )
316 {
317     int i, * pPlace;
318     if ( Vec_WrdSize(p->vObjs) > Vec_IntSize(p->vTable) )
319     {
320         Vec_IntFill( p->vTable, Abc_PrimeCudd(2*Vec_IntSize(p->vTable)), -1 );
321         for ( i = 0; i < Vec_WrdSize(p->vObjs); i++ )
322         {
323             pPlace = Vec_IntEntryP( p->vTable, Hsh_IntManHash(Hsh_IntData(p, Hsh_IntObj(p, i)->iData), p->nSize, Vec_IntSize(p->vTable)) );
324             Hsh_IntObj(p, i)->iNext = *pPlace;  *pPlace = i;
325         }
326     }
327     pPlace = Hsh_IntManLookup( p, Hsh_IntData(p, iData) );
328     if ( *pPlace == -1 )
329     {
330         *pPlace = Vec_WrdSize(p->vObjs);
331         Vec_WrdPush( p->vObjs, Hsh_IntWord(iData, -1) );
332         return Vec_WrdSize(p->vObjs) - 1;
333     }
334     return (word *)Hsh_IntObj(p, *pPlace) - Vec_WrdArray(p->vObjs);
335 }
336 
337 /**Function*************************************************************
338 
339   Synopsis    [Hashes data by value.]
340 
341   Description [Array vData contains data entries, each of 'nSize' integers.
342   The resulting array contains the indexes of unique data entries.]
343 
344   SideEffects []
345 
346   SeeAlso     []
347 
348 ***********************************************************************/
Hsh_IntManHashArray(Vec_Int_t * vData,int nSize)349 static inline Vec_Int_t * Hsh_IntManHashArray( Vec_Int_t * vData, int nSize )
350 {
351     Hsh_IntMan_t * p;
352     Vec_Int_t * vRes = Vec_IntAlloc( 100 );
353     int i, nEntries = Vec_IntSize(vData) / nSize;
354     assert( Vec_IntSize(vData) % nSize == 0 );
355     p = Hsh_IntManStart( vData, nSize, nEntries );
356     for ( i = 0; i < nEntries; i++ )
357         Vec_IntPush( vRes, Hsh_IntManAdd(p, i) );
358     Hsh_IntManStop( p );
359     return vRes;
360 }
Hsh_WrdManHashArray(Vec_Wrd_t * vDataW,int nSize)361 static inline Vec_Int_t * Hsh_WrdManHashArray( Vec_Wrd_t * vDataW, int nSize )
362 {
363     Hsh_IntMan_t * p;
364     Vec_Int_t Data = { 2*Vec_WrdCap(vDataW), 2*Vec_WrdSize(vDataW), (int *)Vec_WrdArray(vDataW) };
365     Vec_Int_t * vData = &Data;
366     Vec_Int_t * vRes = Vec_IntAlloc( 100 );
367     int i, nEntries = Vec_IntSize(vData) / (2*nSize);
368     assert( Vec_IntSize(vData) % (2*nSize) == 0 );
369     p = Hsh_IntManStart( vData, (2*nSize), nEntries );
370     for ( i = 0; i < nEntries; i++ )
371         Vec_IntPush( vRes, Hsh_IntManAdd(p, i) );
372     Hsh_IntManStop( p );
373     return vRes;
374 }
Hsh_WrdManHashArrayStart(Vec_Wrd_t * vDataW,int nSize)375 static inline Hsh_IntMan_t * Hsh_WrdManHashArrayStart( Vec_Wrd_t * vDataW, int nSize )
376 {
377     Hsh_IntMan_t * p;
378     int i, nEntries = Vec_WrdSize(vDataW) / nSize;
379     Vec_Int_t * vData = Vec_IntAlloc( 2*Vec_WrdSize(vDataW) );
380     memcpy( Vec_IntArray(vData), Vec_WrdArray(vDataW), sizeof(word)*(size_t)Vec_WrdSize(vDataW) );
381     vData->nSize = 2*Vec_WrdSize(vDataW);
382 /*
383     for ( i = 0; i < 30; i++ )
384     {
385         extern void Extra_PrintHex( FILE * pFile, unsigned * pTruth, int nVars );
386         Extra_PrintHex( stdout, (unsigned *) Vec_WrdEntryP(vDataW, i), 6 );  printf( "  " );
387         Kit_DsdPrintFromTruth( (unsigned *) Vec_WrdEntryP(vDataW, i), 6 );   printf( "\n" );
388     }
389 */
390     assert( Vec_IntSize(vData) % (2*nSize) == 0 );
391     p = Hsh_IntManStart( vData, (2*nSize), nEntries );
392     for ( i = 0; i < nEntries; i++ )
393         Hsh_IntManAdd( p, i );
394     assert( Vec_WrdSize(p->vObjs) == nEntries );
395     return p;
396 }
397 
398 /**Function*************************************************************
399 
400   Synopsis    [Test procedure.]
401 
402   Description []
403 
404   SideEffects []
405 
406   SeeAlso     []
407 
408 ***********************************************************************/
Hsh_IntManHashArrayTest()409 static inline void Hsh_IntManHashArrayTest()
410 {
411     Vec_Int_t * vData = Vec_IntAlloc( 10 );
412     Vec_Int_t * vRes;
413     Vec_IntPush( vData, 12 );
414     Vec_IntPush( vData, 17 );
415     Vec_IntPush( vData, 13 );
416     Vec_IntPush( vData, 12 );
417     Vec_IntPush( vData, 15 );
418     Vec_IntPush( vData, 3 );
419     Vec_IntPush( vData, 16 );
420     Vec_IntPush( vData, 16 );
421     Vec_IntPush( vData, 12 );
422     Vec_IntPush( vData, 17 );
423     Vec_IntPush( vData, 12 );
424     Vec_IntPush( vData, 12 );
425 
426     vRes = Hsh_IntManHashArray( vData, 2 );
427 
428     Vec_IntPrint( vData );
429     Vec_IntPrint( vRes );
430 
431     Vec_IntFree( vData );
432     Vec_IntFree( vRes );
433 }
434 
435 
436 
437 
438 
439 /**Function*************************************************************
440 
441   Synopsis    [Hashing integer arrays.]
442 
443   Description []
444 
445   SideEffects []
446 
447   SeeAlso     []
448 
449 ***********************************************************************/
Hsh_VecManStart(int nEntries)450 static inline Hsh_VecMan_t * Hsh_VecManStart( int nEntries )
451 {
452     Hsh_VecMan_t * p;
453     p = ABC_CALLOC( Hsh_VecMan_t, 1 );
454     p->vTable = Vec_IntStartFull( Abc_PrimeCudd(nEntries) );
455     p->vData  = Vec_IntAlloc( nEntries * 4 );
456     p->vMap   = Vec_IntAlloc( nEntries );
457     return p;
458 }
Hsh_VecManStop(Hsh_VecMan_t * p)459 static inline void Hsh_VecManStop( Hsh_VecMan_t * p )
460 {
461     Vec_IntFree( p->vTable );
462     Vec_IntFree( p->vData );
463     Vec_IntFree( p->vMap );
464     ABC_FREE( p );
465 }
Hsh_VecReadArray(Hsh_VecMan_t * p,int i)466 static inline int * Hsh_VecReadArray( Hsh_VecMan_t * p, int i )
467 {
468     return (int*)Hsh_VecObj(p, i) + 2;
469 }
Hsh_VecReadEntry(Hsh_VecMan_t * p,int i)470 static inline Vec_Int_t * Hsh_VecReadEntry( Hsh_VecMan_t * p, int i )
471 {
472     Hsh_VecObj_t * pObj = Hsh_VecObj( p, i );
473     p->vTemp.nSize = p->vTemp.nCap = pObj->nSize;
474     p->vTemp.pArray = (int*)pObj + 2;
475     return &p->vTemp;
476 }
Hsh_VecReadEntry1(Hsh_VecMan_t * p,int i)477 static inline Vec_Int_t * Hsh_VecReadEntry1( Hsh_VecMan_t * p, int i )
478 {
479     Hsh_VecObj_t * pObj = Hsh_VecObj( p, i );
480     p->vTemp1.nSize = p->vTemp1.nCap = pObj->nSize;
481     p->vTemp1.pArray = (int*)pObj + 2;
482     return &p->vTemp1;
483 }
Hsh_VecReadEntry2(Hsh_VecMan_t * p,int i)484 static inline Vec_Int_t * Hsh_VecReadEntry2( Hsh_VecMan_t * p, int i )
485 {
486     Hsh_VecObj_t * pObj = Hsh_VecObj( p, i );
487     p->vTemp2.nSize = p->vTemp2.nCap = pObj->nSize;
488     p->vTemp2.pArray = (int*)pObj + 2;
489     return &p->vTemp2;
490 }
Hsh_VecSize(Hsh_VecMan_t * p)491 static inline int Hsh_VecSize( Hsh_VecMan_t * p )
492 {
493     return Vec_IntSize(p->vMap);
494 }
495 
496 /**Function*************************************************************
497 
498   Synopsis    []
499 
500   Description []
501 
502   SideEffects []
503 
504   SeeAlso     []
505 
506 ***********************************************************************/
Hsh_VecManHash(Vec_Int_t * vVec,int nTableSize)507 static inline int Hsh_VecManHash( Vec_Int_t * vVec, int nTableSize )
508 {
509     static unsigned s_Primes[7] = {4177, 5147, 5647, 6343, 7103, 7873, 8147};
510     unsigned Key = 0;
511     int i, Entry;
512     Vec_IntForEachEntry( vVec, Entry, i )
513         Key += (unsigned)Entry * s_Primes[i % 7];
514     return (int)(Key % nTableSize);
515 }
Hsh_VecManAdd(Hsh_VecMan_t * p,Vec_Int_t * vVec)516 static inline int Hsh_VecManAdd( Hsh_VecMan_t * p, Vec_Int_t * vVec )
517 {
518     Hsh_VecObj_t * pObj;
519     int i, Ent, * pPlace;
520     if ( Vec_IntSize(p->vMap) > Vec_IntSize(p->vTable) )
521     {
522         Vec_IntFill( p->vTable, Abc_PrimeCudd(2*Vec_IntSize(p->vTable)), -1 );
523         for ( i = 0; i < Vec_IntSize(p->vMap); i++ )
524         {
525             pPlace = Vec_IntEntryP( p->vTable, Hsh_VecManHash(Hsh_VecReadEntry(p, i), Vec_IntSize(p->vTable)) );
526             Hsh_VecObj(p, i)->iNext = *pPlace; *pPlace = i;
527         }
528     }
529     pPlace = Vec_IntEntryP( p->vTable, Hsh_VecManHash(vVec, Vec_IntSize(p->vTable)) );
530     for ( ; (pObj = Hsh_VecObj(p, *pPlace)); pPlace = &pObj->iNext )
531         if ( pObj->nSize == Vec_IntSize(vVec) && !memcmp( pObj->pArray, Vec_IntArray(vVec), sizeof(int) * (size_t)pObj->nSize ) )
532             return *pPlace;
533     *pPlace = Vec_IntSize(p->vMap);
534     assert( Vec_IntSize(p->vData) % 2 == 0 );
535     Vec_IntPush( p->vMap, Vec_IntSize(p->vData) );
536     Vec_IntPush( p->vData, Vec_IntSize(vVec) );
537     Vec_IntPush( p->vData, -1 );
538     Vec_IntForEachEntry( vVec, Ent, i )
539         Vec_IntPush( p->vData, Ent );
540     if ( Vec_IntSize(vVec) & 1 )
541         Vec_IntPush( p->vData, -1 );
542     return Vec_IntSize(p->vMap) - 1;
543 }
544 
545 /**Function*************************************************************
546 
547   Synopsis    [Test procedure.]
548 
549   Description []
550 
551   SideEffects []
552 
553   SeeAlso     []
554 
555 ***********************************************************************/
Hsh_VecManHashTest()556 static inline void Hsh_VecManHashTest()
557 {
558     Hsh_VecMan_t * p;
559     Vec_Int_t * vTemp;
560     Vec_Int_t * vRes = Vec_IntAlloc( 1000 );
561     int i;
562 
563     p = Hsh_VecManStart( 5 );
564     for ( i = 0; i < 20; i++ )
565     {
566         vTemp = Vec_IntStartNatural( i );
567         Vec_IntPush( vRes, Hsh_VecManAdd( p, vTemp ) );
568         Vec_IntFree( vTemp );
569     }
570     for ( ; i > 0; i-- )
571     {
572         vTemp = Vec_IntStartNatural( i );
573         Vec_IntPush( vRes, Hsh_VecManAdd( p, vTemp ) );
574         Vec_IntFree( vTemp );
575     }
576     Vec_IntPrint( vRes );
577     Vec_IntFree( vRes );
578 
579     Hsh_VecManStop( p );
580 }
581 
582 
583 ////////////////////////////////////////////////////////////////////////
584 ///                       END OF FILE                                ///
585 ////////////////////////////////////////////////////////////////////////
586 
587 ABC_NAMESPACE_HEADER_END
588 
589 #endif
590 
591