1 /**CFile****************************************************************
2 
3   FileName    [vecVec.h]
4 
5   SystemName  [ABC: Logic synthesis and verification system.]
6 
7   PackageName [Resizable arrays.]
8 
9   Synopsis    [Resizable vector of resizable vectors.]
10 
11   Author      [Alan Mishchenko]
12 
13   Affiliation [UC Berkeley]
14 
15   Date        [Ver. 1.0. Started - June 20, 2005.]
16 
17   Revision    [$Id: vecVec.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #ifndef ABC__misc__vec__vecVec_h
22 #define ABC__misc__vec__vecVec_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 Vec_Vec_t_       Vec_Vec_t;
43 struct Vec_Vec_t_
44 {
45     int              nCap;
46     int              nSize;
47     void **          pArray;
48 };
49 
50 ////////////////////////////////////////////////////////////////////////
51 ///                      MACRO DEFINITIONS                           ///
52 ////////////////////////////////////////////////////////////////////////
53 
54 // iterators through levels
55 #define Vec_VecForEachLevel( vGlob, vVec, i )                                                 \
56     for ( i = 0; (i < Vec_VecSize(vGlob)) && (((vVec) = Vec_VecEntry(vGlob, i)), 1); i++ )
57 #define Vec_VecForEachLevelStart( vGlob, vVec, i, LevelStart )                                \
58     for ( i = LevelStart; (i < Vec_VecSize(vGlob)) && (((vVec) = Vec_VecEntry(vGlob, i)), 1); i++ )
59 #define Vec_VecForEachLevelStop( vGlob, vVec, i, LevelStop )                                  \
60     for ( i = 0; (i < LevelStop) && (((vVec) = Vec_VecEntry(vGlob, i)), 1); i++ )
61 #define Vec_VecForEachLevelStartStop( vGlob, vVec, i, LevelStart, LevelStop )                 \
62     for ( i = LevelStart; (i < LevelStop) && (((vVec) = Vec_VecEntry(vGlob, i)), 1); i++ )
63 #define Vec_VecForEachLevelReverse( vGlob, vVec, i )                                          \
64     for ( i = Vec_VecSize(vGlob)-1; (i >= 0) && (((vVec) = Vec_VecEntry(vGlob, i)), 1); i-- )
65 #define Vec_VecForEachLevelReverseStartStop( vGlob, vVec, i, LevelStart, LevelStop )          \
66     for ( i = LevelStart-1; (i >= LevelStop) && (((vVec) = Vec_VecEntry(vGlob, i)), 1); i-- )
67 #define Vec_VecForEachLevelTwo( vGlob1, vGlob2, vVec1, vVec2, i )                                                 \
68     for ( i = 0; (i < Vec_VecSize(vGlob1)) && (((vVec1) = Vec_VecEntry(vGlob1, i)), 1) && (((vVec2) = Vec_VecEntry(vGlob2, i)), 1); i++ )
69 
70 // iterators through levels
71 #define Vec_VecForEachLevelInt( vGlob, vVec, i )                                              \
72     for ( i = 0; (i < Vec_VecSize(vGlob)) && (((vVec) = Vec_VecEntryInt(vGlob, i)), 1); i++ )
73 #define Vec_VecForEachLevelIntStart( vGlob, vVec, i, LevelStart )                             \
74     for ( i = LevelStart; (i < Vec_VecSize(vGlob)) && (((vVec) = Vec_VecEntryInt(vGlob, i)), 1); i++ )
75 #define Vec_VecForEachLevelIntStop( vGlob, vVec, i, LevelStop )                               \
76     for ( i = 0; (i < LevelStop) && (((vVec) = Vec_VecEntryInt(vGlob, i)), 1); i++ )
77 #define Vec_VecForEachLevelIntStartStop( vGlob, vVec, i, LevelStart, LevelStop )              \
78     for ( i = LevelStart; (i < LevelStop) && (((vVec) = Vec_VecEntryInt(vGlob, i)), 1); i++ )
79 #define Vec_VecForEachLevelIntReverse( vGlob, vVec, i )                                       \
80     for ( i = Vec_VecSize(vGlob)-1; (i >= 0) && (((vVec) = Vec_VecEntryInt(vGlob, i)), 1); i-- )
81 #define Vec_VecForEachLevelIntReverseStartStop( vGlob, vVec, i, LevelStart, LevelStop )       \
82     for ( i = LevelStart-1; (i >= LevelStop) && (((vVec) = Vec_VecEntryInt(vGlob, i)), 1); i-- )
83 #define Vec_VecForEachLevelIntTwo( vGlob1, vGlob2, vVec1, vVec2, i )                          \
84     for ( i = 0; (i < Vec_VecSize(vGlob1)) && (((vVec1) = Vec_VecEntryInt(vGlob1, i)), 1) && (((vVec2) = Vec_VecEntryInt(vGlob2, i)), 1); i++ )
85 
86 // iteratores through entries
87 #define Vec_VecForEachEntry( Type, vGlob, pEntry, i, k )                                      \
88     for ( i = 0; i < Vec_VecSize(vGlob); i++ )                                                \
89         Vec_PtrForEachEntry( Type, Vec_VecEntry(vGlob, i), pEntry, k )
90 #define Vec_VecForEachEntryLevel( Type, vGlob, pEntry, i, Level )                             \
91         Vec_PtrForEachEntry( Type, Vec_VecEntry(vGlob, Level), pEntry, i )
92 #define Vec_VecForEachEntryStart( Type, vGlob, pEntry, i, k, LevelStart )                     \
93     for ( i = LevelStart; i < Vec_VecSize(vGlob); i++ )                                       \
94         Vec_PtrForEachEntry( Type, Vec_VecEntry(vGlob, i), pEntry, k )
95 #define Vec_VecForEachEntryStartStop( Type, vGlob, pEntry, i, k, LevelStart, LevelStop )      \
96     for ( i = LevelStart; i < LevelStop; i++ )                                                \
97         Vec_PtrForEachEntry( Type, Vec_VecEntry(vGlob, i), pEntry, k )
98 #define Vec_VecForEachEntryReverse( Type, vGlob, pEntry, i, k )                               \
99     for ( i = 0; i < Vec_VecSize(vGlob); i++ )                                                \
100         Vec_PtrForEachEntryReverse( Type, Vec_VecEntry(vGlob, i), pEntry, k )
101 #define Vec_VecForEachEntryReverseReverse( Type, vGlob, pEntry, i, k )                        \
102     for ( i = Vec_VecSize(vGlob) - 1; i >= 0; i-- )                                           \
103         Vec_PtrForEachEntryReverse( Type, Vec_VecEntry(vGlob, i), pEntry, k )
104 #define Vec_VecForEachEntryReverseStart( Type, vGlob, pEntry, i, k, LevelStart )              \
105     for ( i = LevelStart-1; i >= 0; i-- )                                                     \
106         Vec_PtrForEachEntry( Type, Vec_VecEntry(vGlob, i), pEntry, k )
107 
108 // iteratores through entries
109 #define Vec_VecForEachEntryInt( vGlob, Entry, i, k )                                          \
110     for ( i = 0; i < Vec_VecSize(vGlob); i++ )                                                \
111         Vec_IntForEachEntry( Vec_VecEntryInt(vGlob, i), Entry, k )
112 #define Vec_VecForEachEntryIntLevel( vGlob, Entry, i, Level )                                 \
113         Vec_IntForEachEntry( Vec_VecEntryInt(vGlob, Level), Entry, i )
114 #define Vec_VecForEachEntryIntStart( vGlob, Entry, i, k, LevelStart )                         \
115     for ( i = LevelStart; i < Vec_VecSize(vGlob); i++ )                                       \
116         Vec_IntForEachEntry( Vec_VecEntryInt(vGlob, i), Entry, k )
117 #define Vec_VecForEachEntryIntStartStop( vGlob, Entry, i, k, LevelStart, LevelStop )          \
118     for ( i = LevelStart; i < LevelStop; i++ )                                                \
119         Vec_IntForEachEntry( Vec_VecEntryInt(vGlob, i), Entry, k )
120 #define Vec_VecForEachEntryIntReverse( vGlob, Entry, i, k )                                   \
121     for ( i = 0; i < Vec_VecSize(vGlob); i++ )                                                \
122         Vec_IntForEachEntryReverse( Vec_VecEntryInt(vGlob, i), Entry, k )
123 #define Vec_VecForEachEntryIntReverseReverse( vGlob, Entry, i, k )                            \
124     for ( i = Vec_VecSize(vGlob) - 1; i >= 0; i-- )                                           \
125         Vec_IntForEachEntryReverse( Vec_VecEntryInt(vGlob, i), Entry, k )
126 #define Vec_VecForEachEntryIntReverseStart( vGlob, Entry, i, k, LevelStart )                  \
127     for ( i = LevelStart-1; i >= 0; i-- )                                                     \
128         Vec_IntForEachEntry( Vec_VecEntryInt(vGlob, i), Entry, k )
129 
130 ////////////////////////////////////////////////////////////////////////
131 ///                     FUNCTION DEFINITIONS                         ///
132 ////////////////////////////////////////////////////////////////////////
133 
134 /**Function*************************************************************
135 
136   Synopsis    [Allocates a vector with the given capacity.]
137 
138   Description []
139 
140   SideEffects []
141 
142   SeeAlso     []
143 
144 ***********************************************************************/
Vec_VecAlloc(int nCap)145 static inline Vec_Vec_t * Vec_VecAlloc( int nCap )
146 {
147     Vec_Vec_t * p;
148     p = ABC_ALLOC( Vec_Vec_t, 1 );
149     if ( nCap > 0 && nCap < 8 )
150         nCap = 8;
151     p->nSize  = 0;
152     p->nCap   = nCap;
153     p->pArray = p->nCap? ABC_ALLOC( void *, p->nCap ) : NULL;
154     return p;
155 }
156 
157 /**Function*************************************************************
158 
159   Synopsis    [Allocates a vector with the given capacity.]
160 
161   Description []
162 
163   SideEffects []
164 
165   SeeAlso     []
166 
167 ***********************************************************************/
Vec_VecStart(int nSize)168 static inline Vec_Vec_t * Vec_VecStart( int nSize )
169 {
170     Vec_Vec_t * p;
171     int i;
172     p = Vec_VecAlloc( nSize );
173     for ( i = 0; i < nSize; i++ )
174         p->pArray[i] = Vec_PtrAlloc( 0 );
175     p->nSize = nSize;
176     return p;
177 }
178 
179 /**Function*************************************************************
180 
181   Synopsis    [Allocates a vector with the given capacity.]
182 
183   Description []
184 
185   SideEffects []
186 
187   SeeAlso     []
188 
189 ***********************************************************************/
Vec_VecExpand(Vec_Vec_t * p,int Level)190 static inline void Vec_VecExpand( Vec_Vec_t * p, int Level )
191 {
192     int i;
193     if ( p->nSize >= Level + 1 )
194         return;
195     Vec_PtrGrow( (Vec_Ptr_t *)p, Level + 1 );
196     for ( i = p->nSize; i <= Level; i++ )
197         p->pArray[i] = Vec_PtrAlloc( 0 );
198     p->nSize = Level + 1;
199 }
Vec_VecExpandInt(Vec_Vec_t * p,int Level)200 static inline void Vec_VecExpandInt( Vec_Vec_t * p, int Level )
201 {
202     int i;
203     if ( p->nSize >= Level + 1 )
204         return;
205     Vec_IntGrow( (Vec_Int_t *)p, Level + 1 );
206     for ( i = p->nSize; i <= Level; i++ )
207         p->pArray[i] = Vec_PtrAlloc( 0 );
208     p->nSize = Level + 1;
209 }
210 
211 /**Function*************************************************************
212 
213   Synopsis    []
214 
215   Description []
216 
217   SideEffects []
218 
219   SeeAlso     []
220 
221 ***********************************************************************/
Vec_VecSize(Vec_Vec_t * p)222 static inline int Vec_VecSize( Vec_Vec_t * p )
223 {
224     return p->nSize;
225 }
226 
227 /**Function*************************************************************
228 
229   Synopsis    []
230 
231   Description []
232 
233   SideEffects []
234 
235   SeeAlso     []
236 
237 ***********************************************************************/
Vec_VecCap(Vec_Vec_t * p)238 static inline int Vec_VecCap( Vec_Vec_t * p )
239 {
240     return p->nCap;
241 }
242 
243 /**Function*************************************************************
244 
245   Synopsis    []
246 
247   Description []
248 
249   SideEffects []
250 
251   SeeAlso     []
252 
253 ***********************************************************************/
Vec_VecLevelSize(Vec_Vec_t * p,int i)254 static inline int Vec_VecLevelSize( Vec_Vec_t * p, int i )
255 {
256     assert( i >= 0 && i < p->nSize );
257     return Vec_PtrSize( (Vec_Ptr_t *)p->pArray[i] );
258 }
259 
260 /**Function*************************************************************
261 
262   Synopsis    []
263 
264   Description []
265 
266   SideEffects []
267 
268   SeeAlso     []
269 
270 ***********************************************************************/
Vec_VecEntry(Vec_Vec_t * p,int i)271 static inline Vec_Ptr_t * Vec_VecEntry( Vec_Vec_t * p, int i )
272 {
273     assert( i >= 0 && i < p->nSize );
274     return (Vec_Ptr_t *)p->pArray[i];
275 }
Vec_VecEntryInt(Vec_Vec_t * p,int i)276 static inline Vec_Int_t * Vec_VecEntryInt( Vec_Vec_t * p, int i )
277 {
278     assert( i >= 0 && i < p->nSize );
279     return (Vec_Int_t *)p->pArray[i];
280 }
281 
282 /**Function*************************************************************
283 
284   Synopsis    []
285 
286   Description []
287 
288   SideEffects []
289 
290   SeeAlso     []
291 
292 ***********************************************************************/
Vec_VecMemory(Vec_Vec_t * p)293 static inline double Vec_VecMemory( Vec_Vec_t * p )
294 {
295     int i;
296     double Mem;
297     if ( p == NULL )  return 0.0;
298     Mem = Vec_PtrMemory( (Vec_Ptr_t *)p );
299     for ( i = 0; i < p->nSize; i++ )
300         if ( Vec_VecEntry(p, i) )
301             Mem += Vec_PtrMemory( Vec_VecEntry(p, i) );
302     return Mem;
303 }
Vec_VecMemoryInt(Vec_Vec_t * p)304 static inline double Vec_VecMemoryInt( Vec_Vec_t * p )
305 {
306     int i;
307     double Mem;
308     if ( p == NULL )  return 0.0;
309     Mem = Vec_PtrMemory( (Vec_Ptr_t *)p );
310     for ( i = 0; i < p->nSize; i++ )
311         if ( Vec_VecEntry(p, i) )
312             Mem += Vec_IntMemory( Vec_VecEntryInt(p, i) );
313     return Mem;
314 }
315 
316 /**Function*************************************************************
317 
318   Synopsis    []
319 
320   Description []
321 
322   SideEffects []
323 
324   SeeAlso     []
325 
326 ***********************************************************************/
Vec_VecEntryEntry(Vec_Vec_t * p,int i,int k)327 static inline void * Vec_VecEntryEntry( Vec_Vec_t * p, int i, int k )
328 {
329     return Vec_PtrEntry( Vec_VecEntry(p, i), k );
330 }
Vec_VecEntryEntryInt(Vec_Vec_t * p,int i,int k)331 static inline int Vec_VecEntryEntryInt( Vec_Vec_t * p, int i, int k )
332 {
333     return Vec_IntEntry( Vec_VecEntryInt(p, i), k );
334 }
335 
336 /**Function*************************************************************
337 
338   Synopsis    [Frees the vector.]
339 
340   Description []
341 
342   SideEffects []
343 
344   SeeAlso     []
345 
346 ***********************************************************************/
Vec_VecFree(Vec_Vec_t * p)347 static inline void Vec_VecFree( Vec_Vec_t * p )
348 {
349     Vec_Ptr_t * vVec;
350     int i;
351     Vec_VecForEachLevel( p, vVec, i )
352         if ( vVec ) Vec_PtrFree( vVec );
353     Vec_PtrFree( (Vec_Ptr_t *)p );
354 }
Vec_VecErase(Vec_Vec_t * p)355 static inline void Vec_VecErase( Vec_Vec_t * p )
356 {
357     Vec_Ptr_t * vVec;
358     int i;
359     Vec_VecForEachLevel( p, vVec, i )
360         if ( vVec ) Vec_PtrFree( vVec );
361     Vec_PtrErase( (Vec_Ptr_t *)p );
362 }
363 
364 /**Function*************************************************************
365 
366   Synopsis    []
367 
368   Description []
369 
370   SideEffects []
371 
372   SeeAlso     []
373 
374 ***********************************************************************/
Vec_VecFreeP(Vec_Vec_t ** p)375 static inline void Vec_VecFreeP( Vec_Vec_t ** p )
376 {
377     if ( *p == NULL )
378         return;
379     Vec_VecFree( *p );
380     *p = NULL;
381 }
382 
383 /**Function*************************************************************
384 
385   Synopsis    [Frees the vector.]
386 
387   Description []
388 
389   SideEffects []
390 
391   SeeAlso     []
392 
393 ***********************************************************************/
Vec_VecDup(Vec_Vec_t * p)394 static inline Vec_Vec_t * Vec_VecDup( Vec_Vec_t * p )
395 {
396     Vec_Ptr_t * vNew, * vVec;
397     int i;
398     vNew = Vec_PtrAlloc( Vec_VecSize(p) );
399     Vec_VecForEachLevel( p, vVec, i )
400         Vec_PtrPush( vNew, Vec_PtrDup(vVec) );
401     return (Vec_Vec_t *)vNew;
402 }
Vec_VecDupInt(Vec_Vec_t * p)403 static inline Vec_Vec_t * Vec_VecDupInt( Vec_Vec_t * p )
404 {
405     Vec_Ptr_t * vNew;
406     Vec_Int_t * vVec;
407     int i;
408     vNew = Vec_PtrAlloc( Vec_VecSize(p) );
409     Vec_VecForEachLevelInt( p, vVec, i )
410         Vec_PtrPush( vNew, Vec_IntDup(vVec) );
411     return (Vec_Vec_t *)vNew;
412 }
413 
414 /**Function*************************************************************
415 
416   Synopsis    [Frees the vector of vectors.]
417 
418   Description []
419 
420   SideEffects []
421 
422   SeeAlso     []
423 
424 ***********************************************************************/
Vec_VecSizeSize(Vec_Vec_t * p)425 static inline int Vec_VecSizeSize( Vec_Vec_t * p )
426 {
427     Vec_Ptr_t * vVec;
428     int i, Counter = 0;
429     Vec_VecForEachLevel( p, vVec, i )
430         Counter += vVec->nSize;
431     return Counter;
432 }
433 
434 /**Function*************************************************************
435 
436   Synopsis    []
437 
438   Description []
439 
440   SideEffects []
441 
442   SeeAlso     []
443 
444 ***********************************************************************/
Vec_VecClear(Vec_Vec_t * p)445 static inline void Vec_VecClear( Vec_Vec_t * p )
446 {
447     Vec_Ptr_t * vVec;
448     int i;
449     Vec_VecForEachLevel( p, vVec, i )
450         Vec_PtrClear( vVec );
451 }
452 
453 /**Function*************************************************************
454 
455   Synopsis    []
456 
457   Description []
458 
459   SideEffects []
460 
461   SeeAlso     []
462 
463 ***********************************************************************/
Vec_VecPush(Vec_Vec_t * p,int Level,void * Entry)464 static inline void Vec_VecPush( Vec_Vec_t * p, int Level, void * Entry )
465 {
466     if ( p->nSize < Level + 1 )
467     {
468         int i;
469         Vec_PtrGrow( (Vec_Ptr_t *)p, Level + 1 );
470         for ( i = p->nSize; i < Level + 1; i++ )
471             p->pArray[i] = Vec_PtrAlloc( 0 );
472         p->nSize = Level + 1;
473     }
474     Vec_PtrPush( Vec_VecEntry(p, Level), Entry );
475 }
Vec_VecPushInt(Vec_Vec_t * p,int Level,int Entry)476 static inline void Vec_VecPushInt( Vec_Vec_t * p, int Level, int Entry )
477 {
478     if ( p->nSize < Level + 1 )
479     {
480         int i;
481         Vec_PtrGrow( (Vec_Ptr_t *)p, Level + 1 );
482         for ( i = p->nSize; i < Level + 1; i++ )
483             p->pArray[i] = Vec_IntAlloc( 0 );
484         p->nSize = Level + 1;
485     }
486     Vec_IntPush( Vec_VecEntryInt(p, Level), Entry );
487 }
488 
489 /**Function*************************************************************
490 
491   Synopsis    []
492 
493   Description []
494 
495   SideEffects []
496 
497   SeeAlso     []
498 
499 ***********************************************************************/
Vec_VecPushUnique(Vec_Vec_t * p,int Level,void * Entry)500 static inline void Vec_VecPushUnique( Vec_Vec_t * p, int Level, void * Entry )
501 {
502     if ( p->nSize < Level + 1 )
503         Vec_VecPush( p, Level, Entry );
504     else
505         Vec_PtrPushUnique( Vec_VecEntry(p, Level), Entry );
506 }
Vec_VecPushUniqueInt(Vec_Vec_t * p,int Level,int Entry)507 static inline void Vec_VecPushUniqueInt( Vec_Vec_t * p, int Level, int Entry )
508 {
509     if ( p->nSize < Level + 1 )
510         Vec_VecPushInt( p, Level, Entry );
511     else
512         Vec_IntPushUnique( Vec_VecEntryInt(p, Level), Entry );
513 }
514 
515 /**Function*************************************************************
516 
517   Synopsis    [Comparison procedure for two arrays.]
518 
519   Description []
520 
521   SideEffects []
522 
523   SeeAlso     []
524 
525 ***********************************************************************/
Vec_VecSortCompare1(Vec_Ptr_t ** pp1,Vec_Ptr_t ** pp2)526 static int Vec_VecSortCompare1( Vec_Ptr_t ** pp1, Vec_Ptr_t ** pp2 )
527 {
528     if ( Vec_PtrSize(*pp1) < Vec_PtrSize(*pp2) )
529         return -1;
530     if ( Vec_PtrSize(*pp1) > Vec_PtrSize(*pp2) )
531         return 1;
532     return 0;
533 }
Vec_VecSortCompare2(Vec_Ptr_t ** pp1,Vec_Ptr_t ** pp2)534 static int Vec_VecSortCompare2( Vec_Ptr_t ** pp1, Vec_Ptr_t ** pp2 )
535 {
536     if ( Vec_PtrSize(*pp1) > Vec_PtrSize(*pp2) )
537         return -1;
538     if ( Vec_PtrSize(*pp1) < Vec_PtrSize(*pp2) )
539         return 1;
540     return 0;
541 }
542 
543 /**Function*************************************************************
544 
545   Synopsis    [Sorting the entries by their integer value.]
546 
547   Description []
548 
549   SideEffects []
550 
551   SeeAlso     []
552 
553 ***********************************************************************/
Vec_VecSort(Vec_Vec_t * p,int fReverse)554 static inline void Vec_VecSort( Vec_Vec_t * p, int fReverse )
555 {
556     if ( fReverse )
557         qsort( (void *)p->pArray, (size_t)p->nSize, sizeof(void *),
558                 (int (*)(const void *, const void *)) Vec_VecSortCompare2 );
559     else
560         qsort( (void *)p->pArray, (size_t)p->nSize, sizeof(void *),
561                 (int (*)(const void *, const void *)) Vec_VecSortCompare1 );
562 }
563 
564 /**Function*************************************************************
565 
566   Synopsis    [Comparison procedure for two integers.]
567 
568   Description []
569 
570   SideEffects []
571 
572   SeeAlso     []
573 
574 ***********************************************************************/
Vec_VecSortCompare3(Vec_Int_t ** pp1,Vec_Int_t ** pp2)575 static int Vec_VecSortCompare3( Vec_Int_t ** pp1, Vec_Int_t ** pp2 )
576 {
577     if ( Vec_IntEntry(*pp1,0) < Vec_IntEntry(*pp2,0) )
578         return -1;
579     if ( Vec_IntEntry(*pp1,0) > Vec_IntEntry(*pp2,0) )
580         return 1;
581     return 0;
582 }
Vec_VecSortCompare4(Vec_Int_t ** pp1,Vec_Int_t ** pp2)583 static int Vec_VecSortCompare4( Vec_Int_t ** pp1, Vec_Int_t ** pp2 )
584 {
585     if ( Vec_IntEntry(*pp1,0) > Vec_IntEntry(*pp2,0) )
586         return -1;
587     if ( Vec_IntEntry(*pp1,0) < Vec_IntEntry(*pp2,0) )
588         return 1;
589     return 0;
590 }
591 
592 /**Function*************************************************************
593 
594   Synopsis    [Sorting the entries by their integer value.]
595 
596   Description []
597 
598   SideEffects []
599 
600   SeeAlso     []
601 
602 ***********************************************************************/
Vec_VecSortByFirstInt(Vec_Vec_t * p,int fReverse)603 static inline void Vec_VecSortByFirstInt( Vec_Vec_t * p, int fReverse )
604 {
605     if ( fReverse )
606         qsort( (void *)p->pArray, (size_t)p->nSize, sizeof(void *),
607                 (int (*)(const void *, const void *)) Vec_VecSortCompare4 );
608     else
609         qsort( (void *)p->pArray, (size_t)p->nSize, sizeof(void *),
610                 (int (*)(const void *, const void *)) Vec_VecSortCompare3 );
611 }
612 
613 /**Function*************************************************************
614 
615   Synopsis    []
616 
617   Description []
618 
619   SideEffects []
620 
621   SeeAlso     []
622 
623 ***********************************************************************/
Vec_VecPrintInt(Vec_Vec_t * p,int fSkipSingles)624 static inline void Vec_VecPrintInt( Vec_Vec_t * p, int fSkipSingles )
625 {
626     int i, k, Entry;
627     Vec_VecForEachEntryInt( p, Entry, i, k )
628     {
629         if ( fSkipSingles && Vec_VecLevelSize(p, i) == 1 )
630             break;
631         if ( k == 0 )
632             printf( " %4d : {", i );
633         printf( " %d", Entry );
634         if ( k == Vec_VecLevelSize(p, i) - 1 )
635             printf( " }\n" );
636     }
637 }
638 
639 ABC_NAMESPACE_HEADER_END
640 
641 #endif
642 
643 ////////////////////////////////////////////////////////////////////////
644 ///                       END OF FILE                                ///
645 ////////////////////////////////////////////////////////////////////////
646 
647