1 /**CFile****************************************************************
2
3 FileName [vecInt.h]
4
5 SystemName [ABC: Logic synthesis and verification system.]
6
7 PackageName [Resizable arrays.]
8
9 Synopsis [Resizable arrays of integers.]
10
11 Author [Alan Mishchenko]
12
13 Affiliation [UC Berkeley]
14
15 Date [Ver. 1.0. Started - June 20, 2005.]
16
17 Revision [$Id: vecInt.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18
19 ***********************************************************************/
20
21 #ifndef ABC__misc__vec__vecInt_h
22 #define ABC__misc__vec__vecInt_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_Int_t_ Vec_Int_t;
43 struct Vec_Int_t_
44 {
45 int nCap;
46 int nSize;
47 int * pArray;
48 };
49
50 ////////////////////////////////////////////////////////////////////////
51 /// MACRO DEFINITIONS ///
52 ////////////////////////////////////////////////////////////////////////
53
54 #define Vec_IntForEachEntry( vVec, Entry, i ) \
55 for ( i = 0; (i < Vec_IntSize(vVec)) && (((Entry) = Vec_IntEntry(vVec, i)), 1); i++ )
56 #define Vec_IntForEachEntryStart( vVec, Entry, i, Start ) \
57 for ( i = Start; (i < Vec_IntSize(vVec)) && (((Entry) = Vec_IntEntry(vVec, i)), 1); i++ )
58 #define Vec_IntForEachEntryStop( vVec, Entry, i, Stop ) \
59 for ( i = 0; (i < Stop) && (((Entry) = Vec_IntEntry(vVec, i)), 1); i++ )
60 #define Vec_IntForEachEntryStartStop( vVec, Entry, i, Start, Stop ) \
61 for ( i = Start; (i < Stop) && (((Entry) = Vec_IntEntry(vVec, i)), 1); i++ )
62 #define Vec_IntForEachEntryReverse( vVec, pEntry, i ) \
63 for ( i = Vec_IntSize(vVec) - 1; (i >= 0) && (((pEntry) = Vec_IntEntry(vVec, i)), 1); i-- )
64 #define Vec_IntForEachEntryTwo( vVec1, vVec2, Entry1, Entry2, i ) \
65 for ( i = 0; (i < Vec_IntSize(vVec1)) && (((Entry1) = Vec_IntEntry(vVec1, i)), 1) && (((Entry2) = Vec_IntEntry(vVec2, i)), 1); i++ )
66 #define Vec_IntForEachEntryDouble( vVec, Entry1, Entry2, i ) \
67 for ( i = 0; (i+1 < Vec_IntSize(vVec)) && (((Entry1) = Vec_IntEntry(vVec, i)), 1) && (((Entry2) = Vec_IntEntry(vVec, i+1)), 1); i += 2 )
68 #define Vec_IntForEachEntryDoubleStart( vVec, Entry1, Entry2, i, Start ) \
69 for ( i = Start; (i+1 < Vec_IntSize(vVec)) && (((Entry1) = Vec_IntEntry(vVec, i)), 1) && (((Entry2) = Vec_IntEntry(vVec, i+1)), 1); i += 2 )
70 #define Vec_IntForEachEntryTriple( vVec, Entry1, Entry2, Entry3, i ) \
71 for ( i = 0; (i+2 < Vec_IntSize(vVec)) && (((Entry1) = Vec_IntEntry(vVec, i)), 1) && (((Entry2) = Vec_IntEntry(vVec, i+1)), 1) && (((Entry3) = Vec_IntEntry(vVec, i+2)), 1); i += 3 )
72 #define Vec_IntForEachEntryThisNext( vVec, This, Next, i ) \
73 for ( i = 0, (This) = (Next) = (Vec_IntSize(vVec) ? Vec_IntEntry(vVec, 0) : -1); (i+1 < Vec_IntSize(vVec)) && (((Next) = Vec_IntEntry(vVec, i+1)), 1); i += 2, (This) = (Next) )
74 #define Vec_IntForEachEntryInVec( vVec2, vVec, Entry, i ) \
75 for ( i = 0; (i < Vec_IntSize(vVec)) && (((Entry) = Vec_IntEntry(vVec2, Vec_IntEntry(vVec, i))), 1); i++ )
76
77 ////////////////////////////////////////////////////////////////////////
78 /// FUNCTION DEFINITIONS ///
79 ////////////////////////////////////////////////////////////////////////
80
81 /**Function*************************************************************
82
83 Synopsis [Allocates a vector with the given capacity.]
84
85 Description []
86
87 SideEffects []
88
89 SeeAlso []
90
91 ***********************************************************************/
Vec_IntAlloc(int nCap)92 static inline Vec_Int_t * Vec_IntAlloc( int nCap )
93 {
94 Vec_Int_t * p;
95 p = ABC_ALLOC( Vec_Int_t, 1 );
96 if ( nCap > 0 && nCap < 16 )
97 nCap = 16;
98 p->nSize = 0;
99 p->nCap = nCap;
100 p->pArray = p->nCap? ABC_ALLOC( int, p->nCap ) : NULL;
101 return p;
102 }
Vec_IntAllocExact(int nCap)103 static inline Vec_Int_t * Vec_IntAllocExact( int nCap )
104 {
105 Vec_Int_t * p;
106 assert( nCap >= 0 );
107 p = ABC_ALLOC( Vec_Int_t, 1 );
108 p->nSize = 0;
109 p->nCap = nCap;
110 p->pArray = p->nCap? ABC_ALLOC( int, p->nCap ) : NULL;
111 return p;
112 }
113
114 /**Function*************************************************************
115
116 Synopsis [Allocates a vector with the given size and cleans it.]
117
118 Description []
119
120 SideEffects []
121
122 SeeAlso []
123
124 ***********************************************************************/
Vec_IntStart(int nSize)125 static inline Vec_Int_t * Vec_IntStart( int nSize )
126 {
127 Vec_Int_t * p;
128 p = Vec_IntAlloc( nSize );
129 p->nSize = nSize;
130 if ( p->pArray ) memset( p->pArray, 0, sizeof(int) * (size_t)nSize );
131 return p;
132 }
Vec_IntStartFull(int nSize)133 static inline Vec_Int_t * Vec_IntStartFull( int nSize )
134 {
135 Vec_Int_t * p;
136 p = Vec_IntAlloc( nSize );
137 p->nSize = nSize;
138 if ( p->pArray ) memset( p->pArray, 0xff, sizeof(int) * (size_t)nSize );
139 return p;
140 }
Vec_IntStartRange(int First,int Range)141 static inline Vec_Int_t * Vec_IntStartRange( int First, int Range )
142 {
143 Vec_Int_t * p;
144 int i;
145 p = Vec_IntAlloc( Range );
146 p->nSize = Range;
147 for ( i = 0; i < Range; i++ )
148 p->pArray[i] = First + i;
149 return p;
150 }
151
152 /**Function*************************************************************
153
154 Synopsis [Allocates a vector with the given size and cleans it.]
155
156 Description []
157
158 SideEffects []
159
160 SeeAlso []
161
162 ***********************************************************************/
Vec_IntStartNatural(int nSize)163 static inline Vec_Int_t * Vec_IntStartNatural( int nSize )
164 {
165 Vec_Int_t * p;
166 int i;
167 p = Vec_IntAlloc( nSize );
168 p->nSize = nSize;
169 for ( i = 0; i < nSize; i++ )
170 p->pArray[i] = i;
171 return p;
172 }
173
174 /**Function*************************************************************
175
176 Synopsis [Creates the vector from an integer array of the given size.]
177
178 Description []
179
180 SideEffects []
181
182 SeeAlso []
183
184 ***********************************************************************/
Vec_IntAllocArray(int * pArray,int nSize)185 static inline Vec_Int_t * Vec_IntAllocArray( int * pArray, int nSize )
186 {
187 Vec_Int_t * p;
188 p = ABC_ALLOC( Vec_Int_t, 1 );
189 p->nSize = nSize;
190 p->nCap = nSize;
191 p->pArray = pArray;
192 return p;
193 }
194
195 /**Function*************************************************************
196
197 Synopsis [Creates the vector from an integer array of the given size.]
198
199 Description []
200
201 SideEffects []
202
203 SeeAlso []
204
205 ***********************************************************************/
Vec_IntAllocArrayCopy(int * pArray,int nSize)206 static inline Vec_Int_t * Vec_IntAllocArrayCopy( int * pArray, int nSize )
207 {
208 Vec_Int_t * p;
209 p = ABC_ALLOC( Vec_Int_t, 1 );
210 p->nSize = nSize;
211 p->nCap = nSize;
212 p->pArray = ABC_ALLOC( int, nSize );
213 memcpy( p->pArray, pArray, sizeof(int) * (size_t)nSize );
214 return p;
215 }
216
217 /**Function*************************************************************
218
219 Synopsis [Duplicates the integer array.]
220
221 Description []
222
223 SideEffects []
224
225 SeeAlso []
226
227 ***********************************************************************/
Vec_IntDup(Vec_Int_t * pVec)228 static inline Vec_Int_t * Vec_IntDup( Vec_Int_t * pVec )
229 {
230 Vec_Int_t * p;
231 p = ABC_ALLOC( Vec_Int_t, 1 );
232 p->nSize = pVec->nSize;
233 p->nCap = pVec->nSize;
234 p->pArray = p->nCap? ABC_ALLOC( int, p->nCap ) : NULL;
235 memcpy( p->pArray, pVec->pArray, sizeof(int) * (size_t)pVec->nSize );
236 return p;
237 }
238
239 /**Function*************************************************************
240
241 Synopsis [Transfers the array into another vector.]
242
243 Description []
244
245 SideEffects []
246
247 SeeAlso []
248
249 ***********************************************************************/
Vec_IntDupArray(Vec_Int_t * pVec)250 static inline Vec_Int_t * Vec_IntDupArray( Vec_Int_t * pVec )
251 {
252 Vec_Int_t * p;
253 p = ABC_ALLOC( Vec_Int_t, 1 );
254 p->nSize = pVec->nSize;
255 p->nCap = pVec->nCap;
256 p->pArray = pVec->pArray;
257 pVec->nSize = 0;
258 pVec->nCap = 0;
259 pVec->pArray = NULL;
260 return p;
261 }
262
263 /**Function*************************************************************
264
265 Synopsis []
266
267 Description []
268
269 SideEffects []
270
271 SeeAlso []
272
273 ***********************************************************************/
Vec_IntZero(Vec_Int_t * p)274 static inline void Vec_IntZero( Vec_Int_t * p )
275 {
276 p->pArray = NULL;
277 p->nSize = 0;
278 p->nCap = 0;
279 }
Vec_IntErase(Vec_Int_t * p)280 static inline void Vec_IntErase( Vec_Int_t * p )
281 {
282 ABC_FREE( p->pArray );
283 p->nSize = 0;
284 p->nCap = 0;
285 }
Vec_IntFree(Vec_Int_t * p)286 static inline void Vec_IntFree( Vec_Int_t * p )
287 {
288 ABC_FREE( p->pArray );
289 ABC_FREE( p );
290 }
291
292 /**Function*************************************************************
293
294 Synopsis []
295
296 Description []
297
298 SideEffects []
299
300 SeeAlso []
301
302 ***********************************************************************/
Vec_IntFreeP(Vec_Int_t ** p)303 static inline void Vec_IntFreeP( Vec_Int_t ** p )
304 {
305 if ( *p == NULL )
306 return;
307 ABC_FREE( (*p)->pArray );
308 ABC_FREE( (*p) );
309 }
310
311 /**Function*************************************************************
312
313 Synopsis []
314
315 Description []
316
317 SideEffects []
318
319 SeeAlso []
320
321 ***********************************************************************/
Vec_IntReleaseArray(Vec_Int_t * p)322 static inline int * Vec_IntReleaseArray( Vec_Int_t * p )
323 {
324 int * pArray = p->pArray;
325 p->nCap = 0;
326 p->nSize = 0;
327 p->pArray = NULL;
328 return pArray;
329 }
Vec_IntReleaseNewArray(Vec_Int_t * p)330 static inline int * Vec_IntReleaseNewArray( Vec_Int_t * p )
331 {
332 int * pArray = ABC_ALLOC( int, p->nSize+1 );
333 pArray[0] = p->nSize+1;
334 memcpy( pArray+1, p->pArray, sizeof(int)*(size_t)p->nSize );
335 return pArray;
336 }
337
338 /**Function*************************************************************
339
340 Synopsis []
341
342 Description []
343
344 SideEffects []
345
346 SeeAlso []
347
348 ***********************************************************************/
Vec_IntArray(Vec_Int_t * p)349 static inline int * Vec_IntArray( Vec_Int_t * p )
350 {
351 return p->pArray;
352 }
Vec_IntArrayP(Vec_Int_t * p)353 static inline int ** Vec_IntArrayP( Vec_Int_t * p )
354 {
355 return &p->pArray;
356 }
Vec_IntLimit(Vec_Int_t * p)357 static inline int * Vec_IntLimit( Vec_Int_t * p )
358 {
359 return p->pArray + p->nSize;
360 }
361
362 /**Function*************************************************************
363
364 Synopsis []
365
366 Description []
367
368 SideEffects []
369
370 SeeAlso []
371
372 ***********************************************************************/
Vec_IntSize(Vec_Int_t * p)373 static inline int Vec_IntSize( Vec_Int_t * p )
374 {
375 return p->nSize;
376 }
377
378 /**Function*************************************************************
379
380 Synopsis []
381
382 Description []
383
384 SideEffects []
385
386 SeeAlso []
387
388 ***********************************************************************/
Vec_IntCap(Vec_Int_t * p)389 static inline int Vec_IntCap( Vec_Int_t * p )
390 {
391 return p->nCap;
392 }
393
394 /**Function*************************************************************
395
396 Synopsis []
397
398 Description []
399
400 SideEffects []
401
402 SeeAlso []
403
404 ***********************************************************************/
Vec_IntMemory(Vec_Int_t * p)405 static inline double Vec_IntMemory( Vec_Int_t * p )
406 {
407 return !p ? 0.0 : 1.0 * sizeof(int) * (size_t)p->nCap + sizeof(Vec_Int_t) ;
408 }
409
410 /**Function*************************************************************
411
412 Synopsis []
413
414 Description []
415
416 SideEffects []
417
418 SeeAlso []
419
420 ***********************************************************************/
Vec_IntEntry(Vec_Int_t * p,int i)421 static inline int Vec_IntEntry( Vec_Int_t * p, int i )
422 {
423 assert( i >= 0 && i < p->nSize );
424 return p->pArray[i];
425 }
426
427 /**Function*************************************************************
428
429 Synopsis []
430
431 Description []
432
433 SideEffects []
434
435 SeeAlso []
436
437 ***********************************************************************/
Vec_IntEntryP(Vec_Int_t * p,int i)438 static inline int * Vec_IntEntryP( Vec_Int_t * p, int i )
439 {
440 assert( i >= 0 && i < p->nSize );
441 return p->pArray + i;
442 }
443
444 /**Function*************************************************************
445
446 Synopsis []
447
448 Description []
449
450 SideEffects []
451
452 SeeAlso []
453
454 ***********************************************************************/
Vec_IntWriteEntry(Vec_Int_t * p,int i,int Entry)455 static inline void Vec_IntWriteEntry( Vec_Int_t * p, int i, int Entry )
456 {
457 assert( i >= 0 && i < p->nSize );
458 p->pArray[i] = Entry;
459 }
460
461 /**Function*************************************************************
462
463 Synopsis []
464
465 Description []
466
467 SideEffects []
468
469 SeeAlso []
470
471 ***********************************************************************/
Vec_IntAddToEntry(Vec_Int_t * p,int i,int Addition)472 static inline int Vec_IntAddToEntry( Vec_Int_t * p, int i, int Addition )
473 {
474 assert( i >= 0 && i < p->nSize );
475 return p->pArray[i] += Addition;
476 }
477
478 /**Function*************************************************************
479
480 Synopsis []
481
482 Description []
483
484 SideEffects []
485
486 SeeAlso []
487
488 ***********************************************************************/
Vec_IntUpdateEntry(Vec_Int_t * p,int i,int Value)489 static inline void Vec_IntUpdateEntry( Vec_Int_t * p, int i, int Value )
490 {
491 if ( Vec_IntEntry( p, i ) < Value )
492 Vec_IntWriteEntry( p, i, Value );
493 }
Vec_IntDowndateEntry(Vec_Int_t * p,int i,int Value)494 static inline void Vec_IntDowndateEntry( Vec_Int_t * p, int i, int Value )
495 {
496 if ( Vec_IntEntry( p, i ) > Value )
497 Vec_IntWriteEntry( p, i, Value );
498 }
499
500 /**Function*************************************************************
501
502 Synopsis []
503
504 Description []
505
506 SideEffects []
507
508 SeeAlso []
509
510 ***********************************************************************/
Vec_IntEntryLast(Vec_Int_t * p)511 static inline int Vec_IntEntryLast( Vec_Int_t * p )
512 {
513 assert( p->nSize > 0 );
514 return p->pArray[p->nSize-1];
515 }
516
517 /**Function*************************************************************
518
519 Synopsis [Resizes the vector to the given capacity.]
520
521 Description []
522
523 SideEffects []
524
525 SeeAlso []
526
527 ***********************************************************************/
Vec_IntGrow(Vec_Int_t * p,int nCapMin)528 static inline void Vec_IntGrow( Vec_Int_t * p, int nCapMin )
529 {
530 if ( p->nCap >= nCapMin )
531 return;
532 p->pArray = ABC_REALLOC( int, p->pArray, nCapMin );
533 assert( p->pArray );
534 p->nCap = nCapMin;
535 }
536
537 /**Function*************************************************************
538
539 Synopsis [Resizes the vector to the given capacity.]
540
541 Description []
542
543 SideEffects []
544
545 SeeAlso []
546
547 ***********************************************************************/
Vec_IntGrowResize(Vec_Int_t * p,int nCapMin)548 static inline void Vec_IntGrowResize( Vec_Int_t * p, int nCapMin )
549 {
550 p->nSize = nCapMin;
551 if ( p->nCap >= nCapMin )
552 return;
553 p->pArray = ABC_REALLOC( int, p->pArray, nCapMin );
554 assert( p->pArray );
555 p->nCap = nCapMin;
556 }
557
558 /**Function*************************************************************
559
560 Synopsis [Fills the vector with given number of entries.]
561
562 Description []
563
564 SideEffects []
565
566 SeeAlso []
567
568 ***********************************************************************/
Vec_IntFill(Vec_Int_t * p,int nSize,int Fill)569 static inline void Vec_IntFill( Vec_Int_t * p, int nSize, int Fill )
570 {
571 int i;
572 Vec_IntGrow( p, nSize );
573 for ( i = 0; i < nSize; i++ )
574 p->pArray[i] = Fill;
575 p->nSize = nSize;
576 }
Vec_IntFillTwo(Vec_Int_t * p,int nSize,int FillEven,int FillOdd)577 static inline void Vec_IntFillTwo( Vec_Int_t * p, int nSize, int FillEven, int FillOdd )
578 {
579 int i;
580 Vec_IntGrow( p, nSize );
581 for ( i = 0; i < nSize; i++ )
582 p->pArray[i] = (i & 1) ? FillOdd : FillEven;
583 p->nSize = nSize;
584 }
Vec_IntFillNatural(Vec_Int_t * p,int nSize)585 static inline void Vec_IntFillNatural( Vec_Int_t * p, int nSize )
586 {
587 int i;
588 Vec_IntGrow( p, nSize );
589 for ( i = 0; i < nSize; i++ )
590 p->pArray[i] = i;
591 p->nSize = nSize;
592 }
593
594 /**Function*************************************************************
595
596 Synopsis [Fills the vector with given number of entries.]
597
598 Description []
599
600 SideEffects []
601
602 SeeAlso []
603
604 ***********************************************************************/
Vec_IntFillExtra(Vec_Int_t * p,int nSize,int Fill)605 static inline void Vec_IntFillExtra( Vec_Int_t * p, int nSize, int Fill )
606 {
607 int i;
608 if ( nSize <= p->nSize )
609 return;
610 if ( nSize > 2 * p->nCap )
611 Vec_IntGrow( p, nSize );
612 else if ( nSize > p->nCap )
613 Vec_IntGrow( p, 2 * p->nCap );
614 for ( i = p->nSize; i < nSize; i++ )
615 p->pArray[i] = Fill;
616 p->nSize = nSize;
617 }
618
619 /**Function*************************************************************
620
621 Synopsis [Returns the entry even if the place not exist.]
622
623 Description []
624
625 SideEffects []
626
627 SeeAlso []
628
629 ***********************************************************************/
Vec_IntGetEntry(Vec_Int_t * p,int i)630 static inline int Vec_IntGetEntry( Vec_Int_t * p, int i )
631 {
632 Vec_IntFillExtra( p, i + 1, 0 );
633 return Vec_IntEntry( p, i );
634 }
Vec_IntGetEntryFull(Vec_Int_t * p,int i)635 static inline int Vec_IntGetEntryFull( Vec_Int_t * p, int i )
636 {
637 Vec_IntFillExtra( p, i + 1, -1 );
638 return Vec_IntEntry( p, i );
639 }
640
641 /**Function*************************************************************
642
643 Synopsis [Returns the entry even if the place not exist.]
644
645 Description []
646
647 SideEffects []
648
649 SeeAlso []
650
651 ***********************************************************************/
Vec_IntGetEntryP(Vec_Int_t * p,int i)652 static inline int * Vec_IntGetEntryP( Vec_Int_t * p, int i )
653 {
654 Vec_IntFillExtra( p, i + 1, 0 );
655 return Vec_IntEntryP( p, i );
656 }
657
658 /**Function*************************************************************
659
660 Synopsis [Inserts the entry even if the place does not exist.]
661
662 Description []
663
664 SideEffects []
665
666 SeeAlso []
667
668 ***********************************************************************/
Vec_IntSetEntry(Vec_Int_t * p,int i,int Entry)669 static inline void Vec_IntSetEntry( Vec_Int_t * p, int i, int Entry )
670 {
671 Vec_IntFillExtra( p, i + 1, 0 );
672 Vec_IntWriteEntry( p, i, Entry );
673 }
Vec_IntSetEntryFull(Vec_Int_t * p,int i,int Entry)674 static inline void Vec_IntSetEntryFull( Vec_Int_t * p, int i, int Entry )
675 {
676 Vec_IntFillExtra( p, i + 1, -1 );
677 Vec_IntWriteEntry( p, i, Entry );
678 }
679
680 /**Function*************************************************************
681
682 Synopsis []
683
684 Description []
685
686 SideEffects []
687
688 SeeAlso []
689
690 ***********************************************************************/
Vec_IntShrink(Vec_Int_t * p,int nSizeNew)691 static inline void Vec_IntShrink( Vec_Int_t * p, int nSizeNew )
692 {
693 assert( p->nSize >= nSizeNew );
694 p->nSize = nSizeNew;
695 }
696
697 /**Function*************************************************************
698
699 Synopsis []
700
701 Description []
702
703 SideEffects []
704
705 SeeAlso []
706
707 ***********************************************************************/
Vec_IntClear(Vec_Int_t * p)708 static inline void Vec_IntClear( Vec_Int_t * p )
709 {
710 p->nSize = 0;
711 }
712
713 /**Function*************************************************************
714
715 Synopsis []
716
717 Description []
718
719 SideEffects []
720
721 SeeAlso []
722
723 ***********************************************************************/
Vec_IntPush(Vec_Int_t * p,int Entry)724 static inline void Vec_IntPush( Vec_Int_t * p, int Entry )
725 {
726 if ( p->nSize == p->nCap )
727 {
728 if ( p->nCap < 16 )
729 Vec_IntGrow( p, 16 );
730 else
731 Vec_IntGrow( p, 2 * p->nCap );
732 }
733 p->pArray[p->nSize++] = Entry;
734 }
Vec_IntPushTwo(Vec_Int_t * p,int Entry1,int Entry2)735 static inline void Vec_IntPushTwo( Vec_Int_t * p, int Entry1, int Entry2 )
736 {
737 Vec_IntPush( p, Entry1 );
738 Vec_IntPush( p, Entry2 );
739 }
Vec_IntPushThree(Vec_Int_t * p,int Entry1,int Entry2,int Entry3)740 static inline void Vec_IntPushThree( Vec_Int_t * p, int Entry1, int Entry2, int Entry3 )
741 {
742 Vec_IntPush( p, Entry1 );
743 Vec_IntPush( p, Entry2 );
744 Vec_IntPush( p, Entry3 );
745 }
Vec_IntPushFour(Vec_Int_t * p,int Entry1,int Entry2,int Entry3,int Entry4)746 static inline void Vec_IntPushFour( Vec_Int_t * p, int Entry1, int Entry2, int Entry3, int Entry4 )
747 {
748 Vec_IntPush( p, Entry1 );
749 Vec_IntPush( p, Entry2 );
750 Vec_IntPush( p, Entry3 );
751 Vec_IntPush( p, Entry4 );
752 }
Vec_IntPushArray(Vec_Int_t * p,int * pEntries,int nEntries)753 static inline void Vec_IntPushArray( Vec_Int_t * p, int * pEntries, int nEntries )
754 {
755 int i;
756 for ( i = 0; i < nEntries; i++ )
757 Vec_IntPush( p, pEntries[i] );
758 }
759
760 /**Function*************************************************************
761
762 Synopsis []
763
764 Description []
765
766 SideEffects []
767
768 SeeAlso []
769
770 ***********************************************************************/
Vec_IntPushFirst(Vec_Int_t * p,int Entry)771 static inline void Vec_IntPushFirst( Vec_Int_t * p, int Entry )
772 {
773 int i;
774 if ( p->nSize == p->nCap )
775 {
776 if ( p->nCap < 16 )
777 Vec_IntGrow( p, 16 );
778 else
779 Vec_IntGrow( p, 2 * p->nCap );
780 }
781 p->nSize++;
782 for ( i = p->nSize - 1; i >= 1; i-- )
783 p->pArray[i] = p->pArray[i-1];
784 p->pArray[0] = Entry;
785 }
786
787 /**Function*************************************************************
788
789 Synopsis [Inserts the entry while preserving the increasing order.]
790
791 Description []
792
793 SideEffects []
794
795 SeeAlso []
796
797 ***********************************************************************/
Vec_IntPushOrder(Vec_Int_t * p,int Entry)798 static inline void Vec_IntPushOrder( Vec_Int_t * p, int Entry )
799 {
800 int i;
801 if ( p->nSize == p->nCap )
802 {
803 if ( p->nCap < 16 )
804 Vec_IntGrow( p, 16 );
805 else
806 Vec_IntGrow( p, 2 * p->nCap );
807 }
808 p->nSize++;
809 for ( i = p->nSize-2; i >= 0; i-- )
810 if ( p->pArray[i] > Entry )
811 p->pArray[i+1] = p->pArray[i];
812 else
813 break;
814 p->pArray[i+1] = Entry;
815 }
Vec_IntPushOrderCost(Vec_Int_t * p,int Entry,Vec_Int_t * vCost)816 static inline void Vec_IntPushOrderCost( Vec_Int_t * p, int Entry, Vec_Int_t * vCost )
817 {
818 int i;
819 if ( p->nSize == p->nCap )
820 {
821 if ( p->nCap < 16 )
822 Vec_IntGrow( p, 16 );
823 else
824 Vec_IntGrow( p, 2 * p->nCap );
825 }
826 p->nSize++;
827 for ( i = p->nSize-2; i >= 0; i-- )
828 if ( Vec_IntEntry(vCost, p->pArray[i]) > Vec_IntEntry(vCost, Entry) )
829 p->pArray[i+1] = p->pArray[i];
830 else
831 break;
832 p->pArray[i+1] = Entry;
833 }
834
835 /**Function*************************************************************
836
837 Synopsis [Inserts the entry while preserving the increasing order.]
838
839 Description []
840
841 SideEffects []
842
843 SeeAlso []
844
845 ***********************************************************************/
Vec_IntPushOrderReverse(Vec_Int_t * p,int Entry)846 static inline void Vec_IntPushOrderReverse( Vec_Int_t * p, int Entry )
847 {
848 int i;
849 if ( p->nSize == p->nCap )
850 {
851 if ( p->nCap < 16 )
852 Vec_IntGrow( p, 16 );
853 else
854 Vec_IntGrow( p, 2 * p->nCap );
855 }
856 p->nSize++;
857 for ( i = p->nSize-2; i >= 0; i-- )
858 if ( p->pArray[i] < Entry )
859 p->pArray[i+1] = p->pArray[i];
860 else
861 break;
862 p->pArray[i+1] = Entry;
863 }
864
865 /**Function*************************************************************
866
867 Synopsis [Inserts the entry while preserving the increasing order.]
868
869 Description []
870
871 SideEffects []
872
873 SeeAlso []
874
875 ***********************************************************************/
Vec_IntPushUniqueOrder(Vec_Int_t * p,int Entry)876 static inline int Vec_IntPushUniqueOrder( Vec_Int_t * p, int Entry )
877 {
878 int i;
879 for ( i = 0; i < p->nSize; i++ )
880 if ( p->pArray[i] == Entry )
881 return 1;
882 Vec_IntPushOrder( p, Entry );
883 return 0;
884 }
Vec_IntPushUniqueOrderCost(Vec_Int_t * p,int Entry,Vec_Int_t * vCost)885 static inline int Vec_IntPushUniqueOrderCost( Vec_Int_t * p, int Entry, Vec_Int_t * vCost )
886 {
887 int i;
888 for ( i = 0; i < p->nSize; i++ )
889 if ( p->pArray[i] == Entry )
890 return 1;
891 Vec_IntPushOrderCost( p, Entry, vCost );
892 return 0;
893 }
894
895 /**Function*************************************************************
896
897 Synopsis []
898
899 Description []
900
901 SideEffects []
902
903 SeeAlso []
904
905 ***********************************************************************/
Vec_IntPushUnique(Vec_Int_t * p,int Entry)906 static inline int Vec_IntPushUnique( Vec_Int_t * p, int Entry )
907 {
908 int i;
909 for ( i = 0; i < p->nSize; i++ )
910 if ( p->pArray[i] == Entry )
911 return 1;
912 Vec_IntPush( p, Entry );
913 return 0;
914 }
915
916 /**Function*************************************************************
917
918 Synopsis [Returns the pointer to the next nWords entries in the vector.]
919
920 Description []
921
922 SideEffects []
923
924 SeeAlso []
925
926 ***********************************************************************/
Vec_IntFetch(Vec_Int_t * p,int nWords)927 static inline unsigned * Vec_IntFetch( Vec_Int_t * p, int nWords )
928 {
929 if ( nWords == 0 )
930 return NULL;
931 assert( nWords > 0 );
932 p->nSize += nWords;
933 if ( p->nSize > p->nCap )
934 {
935 // Vec_IntGrow( p, 2 * p->nSize );
936 return NULL;
937 }
938 return ((unsigned *)p->pArray) + p->nSize - nWords;
939 }
940
941 /**Function*************************************************************
942
943 Synopsis [Returns the last entry and removes it from the list.]
944
945 Description []
946
947 SideEffects []
948
949 SeeAlso []
950
951 ***********************************************************************/
Vec_IntPop(Vec_Int_t * p)952 static inline int Vec_IntPop( Vec_Int_t * p )
953 {
954 assert( p->nSize > 0 );
955 return p->pArray[--p->nSize];
956 }
957
958 /**Function*************************************************************
959
960 Synopsis [Find entry.]
961
962 Description []
963
964 SideEffects []
965
966 SeeAlso []
967
968 ***********************************************************************/
Vec_IntFind(Vec_Int_t * p,int Entry)969 static inline int Vec_IntFind( Vec_Int_t * p, int Entry )
970 {
971 int i;
972 for ( i = 0; i < p->nSize; i++ )
973 if ( p->pArray[i] == Entry )
974 return i;
975 return -1;
976 }
977
978 /**Function*************************************************************
979
980 Synopsis []
981
982 Description []
983
984 SideEffects []
985
986 SeeAlso []
987
988 ***********************************************************************/
Vec_IntRemove(Vec_Int_t * p,int Entry)989 static inline int Vec_IntRemove( Vec_Int_t * p, int Entry )
990 {
991 int i;
992 for ( i = 0; i < p->nSize; i++ )
993 if ( p->pArray[i] == Entry )
994 break;
995 if ( i == p->nSize )
996 return 0;
997 assert( i < p->nSize );
998 for ( i++; i < p->nSize; i++ )
999 p->pArray[i-1] = p->pArray[i];
1000 p->nSize--;
1001 return 1;
1002 }
Vec_IntRemove1(Vec_Int_t * p,int Entry)1003 static inline int Vec_IntRemove1( Vec_Int_t * p, int Entry )
1004 {
1005 int i;
1006 for ( i = 1; i < p->nSize; i++ )
1007 if ( p->pArray[i] == Entry )
1008 break;
1009 if ( i >= p->nSize )
1010 return 0;
1011 assert( i < p->nSize );
1012 for ( i++; i < p->nSize; i++ )
1013 p->pArray[i-1] = p->pArray[i];
1014 p->nSize--;
1015 return 1;
1016 }
1017
1018 /**Function*************************************************************
1019
1020 Synopsis []
1021
1022 Description []
1023
1024 SideEffects []
1025
1026 SeeAlso []
1027
1028 ***********************************************************************/
Vec_IntDrop(Vec_Int_t * p,int i)1029 static inline void Vec_IntDrop( Vec_Int_t * p, int i )
1030 {
1031 int k;
1032 assert( i >= 0 && i < Vec_IntSize(p) );
1033 p->nSize--;
1034 for ( k = i; k < p->nSize; k++ )
1035 p->pArray[k] = p->pArray[k+1];
1036 }
1037
1038 /**Function*************************************************************
1039
1040 Synopsis [Interts entry at the index iHere. Shifts other entries.]
1041
1042 Description []
1043
1044 SideEffects []
1045
1046 SeeAlso []
1047
1048 ***********************************************************************/
Vec_IntInsert(Vec_Int_t * p,int iHere,int Entry)1049 static inline void Vec_IntInsert( Vec_Int_t * p, int iHere, int Entry )
1050 {
1051 int i;
1052 assert( iHere >= 0 && iHere <= p->nSize );
1053 Vec_IntPush( p, 0 );
1054 for ( i = p->nSize - 1; i > iHere; i-- )
1055 p->pArray[i] = p->pArray[i-1];
1056 p->pArray[i] = Entry;
1057 }
1058
1059 /**Function*************************************************************
1060
1061 Synopsis [Find entry.]
1062
1063 Description []
1064
1065 SideEffects []
1066
1067 SeeAlso []
1068
1069 ***********************************************************************/
Vec_IntFindMax(Vec_Int_t * p)1070 static inline int Vec_IntFindMax( Vec_Int_t * p )
1071 {
1072 int i, Best;
1073 if ( p->nSize == 0 )
1074 return 0;
1075 Best = p->pArray[0];
1076 for ( i = 1; i < p->nSize; i++ )
1077 if ( Best < p->pArray[i] )
1078 Best = p->pArray[i];
1079 return Best;
1080 }
1081
1082 /**Function*************************************************************
1083
1084 Synopsis [Find entry.]
1085
1086 Description []
1087
1088 SideEffects []
1089
1090 SeeAlso []
1091
1092 ***********************************************************************/
Vec_IntFindMin(Vec_Int_t * p)1093 static inline int Vec_IntFindMin( Vec_Int_t * p )
1094 {
1095 int i, Best;
1096 if ( p->nSize == 0 )
1097 return 0;
1098 Best = p->pArray[0];
1099 for ( i = 1; i < p->nSize; i++ )
1100 if ( Best > p->pArray[i] )
1101 Best = p->pArray[i];
1102 return Best;
1103 }
1104
1105 /**Function*************************************************************
1106
1107 Synopsis [Reverses the order of entries.]
1108
1109 Description []
1110
1111 SideEffects []
1112
1113 SeeAlso []
1114
1115 ***********************************************************************/
Vec_IntReverseOrder(Vec_Int_t * p)1116 static inline void Vec_IntReverseOrder( Vec_Int_t * p )
1117 {
1118 int i, Temp;
1119 for ( i = 0; i < p->nSize/2; i++ )
1120 {
1121 Temp = p->pArray[i];
1122 p->pArray[i] = p->pArray[p->nSize-1-i];
1123 p->pArray[p->nSize-1-i] = Temp;
1124 }
1125 }
1126
1127 /**Function*************************************************************
1128
1129 Synopsis [Removes odd entries.]
1130
1131 Description []
1132
1133 SideEffects []
1134
1135 SeeAlso []
1136
1137 ***********************************************************************/
Vec_IntRemoveOdd(Vec_Int_t * p)1138 static inline void Vec_IntRemoveOdd( Vec_Int_t * p )
1139 {
1140 int i;
1141 assert( (p->nSize & 1) == 0 );
1142 p->nSize >>= 1;
1143 for ( i = 0; i < p->nSize; i++ )
1144 p->pArray[i] = p->pArray[2*i];
1145 }
Vec_IntRemoveEven(Vec_Int_t * p)1146 static inline void Vec_IntRemoveEven( Vec_Int_t * p )
1147 {
1148 int i;
1149 assert( (p->nSize & 1) == 0 );
1150 p->nSize >>= 1;
1151 for ( i = 0; i < p->nSize; i++ )
1152 p->pArray[i] = p->pArray[2*i+1];
1153 }
1154
1155 /**Function*************************************************************
1156
1157 Synopsis []
1158
1159 Description []
1160
1161 SideEffects []
1162
1163 SeeAlso []
1164
1165 ***********************************************************************/
Vec_IntInvert(Vec_Int_t * p,int Fill)1166 static inline Vec_Int_t * Vec_IntInvert( Vec_Int_t * p, int Fill )
1167 {
1168 int Entry, i;
1169 Vec_Int_t * vRes = Vec_IntAlloc( 0 );
1170 if ( Vec_IntSize(p) == 0 )
1171 return vRes;
1172 Vec_IntFill( vRes, Vec_IntFindMax(p) + 1, Fill );
1173 Vec_IntForEachEntry( p, Entry, i )
1174 if ( Entry != Fill )
1175 Vec_IntWriteEntry( vRes, Entry, i );
1176 return vRes;
1177 }
1178
1179 /**Function*************************************************************
1180
1181 Synopsis []
1182
1183 Description []
1184
1185 SideEffects []
1186
1187 SeeAlso []
1188
1189 ***********************************************************************/
Vec_IntCondense(Vec_Int_t * p,int Fill)1190 static inline Vec_Int_t * Vec_IntCondense( Vec_Int_t * p, int Fill )
1191 {
1192 int Entry, i;
1193 Vec_Int_t * vRes = Vec_IntAlloc( Vec_IntSize(p) );
1194 Vec_IntForEachEntry( p, Entry, i )
1195 if ( Entry != Fill )
1196 Vec_IntPush( vRes, Entry );
1197 return vRes;
1198 }
1199
1200 /**Function*************************************************************
1201
1202 Synopsis []
1203
1204 Description []
1205
1206 SideEffects []
1207
1208 SeeAlso []
1209
1210 ***********************************************************************/
Vec_IntSum(Vec_Int_t * p)1211 static inline int Vec_IntSum( Vec_Int_t * p )
1212 {
1213 int i, Counter = 0;
1214 for ( i = 0; i < p->nSize; i++ )
1215 Counter += p->pArray[i];
1216 return Counter;
1217 }
1218
1219 /**Function*************************************************************
1220
1221 Synopsis []
1222
1223 Description []
1224
1225 SideEffects []
1226
1227 SeeAlso []
1228
1229 ***********************************************************************/
Vec_IntCountEntry(Vec_Int_t * p,int Entry)1230 static inline int Vec_IntCountEntry( Vec_Int_t * p, int Entry )
1231 {
1232 int i, Counter = 0;
1233 for ( i = 0; i < p->nSize; i++ )
1234 Counter += (p->pArray[i] == Entry);
1235 return Counter;
1236 }
Vec_IntCountLarger(Vec_Int_t * p,int Entry)1237 static inline int Vec_IntCountLarger( Vec_Int_t * p, int Entry )
1238 {
1239 int i, Counter = 0;
1240 for ( i = 0; i < p->nSize; i++ )
1241 Counter += (p->pArray[i] > Entry);
1242 return Counter;
1243 }
Vec_IntCountSmaller(Vec_Int_t * p,int Entry)1244 static inline int Vec_IntCountSmaller( Vec_Int_t * p, int Entry )
1245 {
1246 int i, Counter = 0;
1247 for ( i = 0; i < p->nSize; i++ )
1248 Counter += (p->pArray[i] < Entry);
1249 return Counter;
1250 }
1251
1252 /**Function*************************************************************
1253
1254 Synopsis []
1255
1256 Description []
1257
1258 SideEffects []
1259
1260 SeeAlso []
1261
1262 ***********************************************************************/
Vec_IntCountPositive(Vec_Int_t * p)1263 static inline int Vec_IntCountPositive( Vec_Int_t * p )
1264 {
1265 int i, Counter = 0;
1266 for ( i = 0; i < p->nSize; i++ )
1267 Counter += (p->pArray[i] > 0);
1268 return Counter;
1269 }
Vec_IntCountZero(Vec_Int_t * p)1270 static inline int Vec_IntCountZero( Vec_Int_t * p )
1271 {
1272 int i, Counter = 0;
1273 for ( i = 0; i < p->nSize; i++ )
1274 Counter += (p->pArray[i] == 0);
1275 return Counter;
1276 }
1277
1278 /**Function*************************************************************
1279
1280 Synopsis [Checks if two vectors are equal.]
1281
1282 Description []
1283
1284 SideEffects []
1285
1286 SeeAlso []
1287
1288 ***********************************************************************/
Vec_IntEqual(Vec_Int_t * p1,Vec_Int_t * p2)1289 static inline int Vec_IntEqual( Vec_Int_t * p1, Vec_Int_t * p2 )
1290 {
1291 int i;
1292 if ( p1->nSize != p2->nSize )
1293 return 0;
1294 for ( i = 0; i < p1->nSize; i++ )
1295 if ( p1->pArray[i] != p2->pArray[i] )
1296 return 0;
1297 return 1;
1298 }
1299
1300 /**Function*************************************************************
1301
1302 Synopsis [Counts the number of common entries.]
1303
1304 Description [Assumes that the entries are non-negative integers that
1305 are not very large, so inversion of the array can be performed.]
1306
1307 SideEffects []
1308
1309 SeeAlso []
1310
1311 ***********************************************************************/
Vec_IntCountCommon(Vec_Int_t * p1,Vec_Int_t * p2)1312 static inline int Vec_IntCountCommon( Vec_Int_t * p1, Vec_Int_t * p2 )
1313 {
1314 Vec_Int_t * vTemp;
1315 int Entry, i, Counter = 0;
1316 if ( Vec_IntSize(p1) < Vec_IntSize(p2) )
1317 vTemp = p1, p1 = p2, p2 = vTemp;
1318 assert( Vec_IntSize(p1) >= Vec_IntSize(p2) );
1319 vTemp = Vec_IntInvert( p2, -1 );
1320 Vec_IntFillExtra( vTemp, Vec_IntFindMax(p1) + 1, -1 );
1321 Vec_IntForEachEntry( p1, Entry, i )
1322 if ( Vec_IntEntry(vTemp, Entry) >= 0 )
1323 Counter++;
1324 Vec_IntFree( vTemp );
1325 return Counter;
1326 }
1327
1328 /**Function*************************************************************
1329
1330 Synopsis [Comparison procedure for two integers.]
1331
1332 Description []
1333
1334 SideEffects []
1335
1336 SeeAlso []
1337
1338 ***********************************************************************/
Vec_IntSortCompare1(int * pp1,int * pp2)1339 static int Vec_IntSortCompare1( int * pp1, int * pp2 )
1340 {
1341 // for some reason commenting out lines (as shown) led to crashing of the release version
1342 if ( *pp1 < *pp2 )
1343 return -1;
1344 if ( *pp1 > *pp2 ) //
1345 return 1;
1346 return 0; //
1347 }
1348
1349 /**Function*************************************************************
1350
1351 Synopsis [Comparison procedure for two integers.]
1352
1353 Description []
1354
1355 SideEffects []
1356
1357 SeeAlso []
1358
1359 ***********************************************************************/
Vec_IntSortCompare2(int * pp1,int * pp2)1360 static int Vec_IntSortCompare2( int * pp1, int * pp2 )
1361 {
1362 // for some reason commenting out lines (as shown) led to crashing of the release version
1363 if ( *pp1 > *pp2 )
1364 return -1;
1365 if ( *pp1 < *pp2 ) //
1366 return 1;
1367 return 0; //
1368 }
1369
1370 /**Function*************************************************************
1371
1372 Synopsis [Sorting the entries by their integer value.]
1373
1374 Description []
1375
1376 SideEffects []
1377
1378 SeeAlso []
1379
1380 ***********************************************************************/
Vec_IntSort(Vec_Int_t * p,int fReverse)1381 static inline void Vec_IntSort( Vec_Int_t * p, int fReverse )
1382 {
1383 if ( fReverse )
1384 qsort( (void *)p->pArray, (size_t)p->nSize, sizeof(int),
1385 (int (*)(const void *, const void *)) Vec_IntSortCompare2 );
1386 else
1387 qsort( (void *)p->pArray, (size_t)p->nSize, sizeof(int),
1388 (int (*)(const void *, const void *)) Vec_IntSortCompare1 );
1389 }
Vec_IntSortMulti(Vec_Int_t * p,int nMulti,int fReverse)1390 static inline void Vec_IntSortMulti( Vec_Int_t * p, int nMulti, int fReverse )
1391 {
1392 assert( Vec_IntSize(p) % nMulti == 0 );
1393 if ( fReverse )
1394 qsort( (void *)p->pArray, (size_t)(p->nSize/nMulti), nMulti*sizeof(int),
1395 (int (*)(const void *, const void *)) Vec_IntSortCompare2 );
1396 else
1397 qsort( (void *)p->pArray, (size_t)(p->nSize/nMulti), nMulti*sizeof(int),
1398 (int (*)(const void *, const void *)) Vec_IntSortCompare1 );
1399 }
1400
1401 /**Function*************************************************************
1402
1403 Synopsis [Leaves only unique entries.]
1404
1405 Description [Returns the number of duplicated entried found.]
1406
1407 SideEffects []
1408
1409 SeeAlso []
1410
1411 ***********************************************************************/
Vec_IntUniqify(Vec_Int_t * p)1412 static inline int Vec_IntUniqify( Vec_Int_t * p )
1413 {
1414 int i, k, RetValue;
1415 if ( p->nSize < 2 )
1416 return 0;
1417 Vec_IntSort( p, 0 );
1418 for ( i = k = 1; i < p->nSize; i++ )
1419 if ( p->pArray[i] != p->pArray[i-1] )
1420 p->pArray[k++] = p->pArray[i];
1421 RetValue = p->nSize - k;
1422 p->nSize = k;
1423 return RetValue;
1424 }
Vec_IntCountDuplicates(Vec_Int_t * p)1425 static inline int Vec_IntCountDuplicates( Vec_Int_t * p )
1426 {
1427 int RetValue;
1428 Vec_Int_t * pDup = Vec_IntDup( p );
1429 Vec_IntUniqify( pDup );
1430 RetValue = Vec_IntSize(p) - Vec_IntSize(pDup);
1431 Vec_IntFree( pDup );
1432 return RetValue;
1433 }
Vec_IntCheckUniqueSmall(Vec_Int_t * p)1434 static inline int Vec_IntCheckUniqueSmall( Vec_Int_t * p )
1435 {
1436 int i, k;
1437 for ( i = 0; i < p->nSize; i++ )
1438 for ( k = i+1; k < p->nSize; k++ )
1439 if ( p->pArray[i] == p->pArray[k] )
1440 return 0;
1441 return 1;
1442 }
Vec_IntCountUnique(Vec_Int_t * p)1443 static inline int Vec_IntCountUnique( Vec_Int_t * p )
1444 {
1445 int i, Count = 0, Max = Vec_IntFindMax(p);
1446 unsigned char * pPres = ABC_CALLOC( unsigned char, Max+1 );
1447 for ( i = 0; i < p->nSize; i++ )
1448 if ( pPres[p->pArray[i]] == 0 )
1449 pPres[p->pArray[i]] = 1, Count++;
1450 ABC_FREE( pPres );
1451 return Count;
1452 }
1453
1454 /**Function*************************************************************
1455
1456 Synopsis [Counts the number of unique pairs.]
1457
1458 Description []
1459
1460 SideEffects []
1461
1462 SeeAlso []
1463
1464 ***********************************************************************/
Vec_IntUniqifyPairs(Vec_Int_t * p)1465 static inline int Vec_IntUniqifyPairs( Vec_Int_t * p )
1466 {
1467 int i, k, RetValue;
1468 assert( p->nSize % 2 == 0 );
1469 if ( p->nSize < 4 )
1470 return 0;
1471 Vec_IntSortMulti( p, 2, 0 );
1472 for ( i = k = 1; i < p->nSize/2; i++ )
1473 if ( p->pArray[2*i] != p->pArray[2*(i-1)] || p->pArray[2*i+1] != p->pArray[2*(i-1)+1] )
1474 {
1475 p->pArray[2*k] = p->pArray[2*i];
1476 p->pArray[2*k+1] = p->pArray[2*i+1];
1477 k++;
1478 }
1479 RetValue = p->nSize/2 - k;
1480 p->nSize = 2*k;
1481 return RetValue;
1482 }
1483
1484 /**Function*************************************************************
1485
1486 Synopsis [Counts the number of unique entries.]
1487
1488 Description []
1489
1490 SideEffects []
1491
1492 SeeAlso []
1493
1494 ***********************************************************************/
Vec_IntUniqueHashKeyDebug(unsigned char * pStr,int nChars,int TableMask)1495 static inline unsigned Vec_IntUniqueHashKeyDebug( unsigned char * pStr, int nChars, int TableMask )
1496 {
1497 static unsigned s_BigPrimes[4] = {12582917, 25165843, 50331653, 100663319};
1498 unsigned Key = 0; int c;
1499 for ( c = 0; c < nChars; c++ )
1500 {
1501 Key += (unsigned)pStr[c] * s_BigPrimes[c & 3];
1502 printf( "%d : ", c );
1503 printf( "%3d ", pStr[c] );
1504 printf( "%12u ", Key );
1505 printf( "%12u ", Key&TableMask );
1506 printf( "\n" );
1507 }
1508 return Key;
1509 }
Vec_IntUniqueProfile(Vec_Int_t * vData,int * pTable,int * pNexts,int TableMask,int nIntSize)1510 static inline void Vec_IntUniqueProfile( Vec_Int_t * vData, int * pTable, int * pNexts, int TableMask, int nIntSize )
1511 {
1512 int i, Key, Counter;
1513 for ( i = 0; i <= TableMask; i++ )
1514 {
1515 Counter = 0;
1516 for ( Key = pTable[i]; Key != -1; Key = pNexts[Key] )
1517 Counter++;
1518 if ( Counter < 7 )
1519 continue;
1520 printf( "%d\n", Counter );
1521 for ( Key = pTable[i]; Key != -1; Key = pNexts[Key] )
1522 {
1523 // Extra_PrintBinary( stdout, (unsigned *)Vec_IntEntryP(vData, Key*nIntSize), 40 ), printf( "\n" );
1524 // Vec_IntUniqueHashKeyDebug( (unsigned char *)Vec_IntEntryP(vData, Key*nIntSize), 4*nIntSize, TableMask );
1525 }
1526 }
1527 printf( "\n" );
1528 }
1529
Vec_IntUniqueHashKey2(unsigned char * pStr,int nChars)1530 static inline unsigned Vec_IntUniqueHashKey2( unsigned char * pStr, int nChars )
1531 {
1532 static unsigned s_BigPrimes[4] = {12582917, 25165843, 50331653, 100663319};
1533 unsigned Key = 0; int c;
1534 for ( c = 0; c < nChars; c++ )
1535 Key += (unsigned)pStr[c] * s_BigPrimes[c & 3];
1536 return Key;
1537 }
1538
Vec_IntUniqueHashKey(unsigned char * pStr,int nChars)1539 static inline unsigned Vec_IntUniqueHashKey( unsigned char * pStr, int nChars )
1540 {
1541 static unsigned s_BigPrimes[16] =
1542 {
1543 0x984b6ad9,0x18a6eed3,0x950353e2,0x6222f6eb,0xdfbedd47,0xef0f9023,0xac932a26,0x590eaf55,
1544 0x97d0a034,0xdc36cd2e,0x22736b37,0xdc9066b0,0x2eb2f98b,0x5d9c7baf,0x85747c9e,0x8aca1055
1545 };
1546 static unsigned s_BigPrimes2[16] =
1547 {
1548 0x8d8a5ebe,0x1e6a15dc,0x197d49db,0x5bab9c89,0x4b55dea7,0x55dede49,0x9a6a8080,0xe5e51035,
1549 0xe148d658,0x8a17eb3b,0xe22e4b38,0xe5be2a9a,0xbe938cbb,0x3b981069,0x7f9c0c8e,0xf756df10
1550 };
1551 unsigned Key = 0; int c;
1552 for ( c = 0; c < nChars; c++ )
1553 Key += s_BigPrimes2[(2*c)&15] * s_BigPrimes[(unsigned)pStr[c] & 15] +
1554 s_BigPrimes2[(2*c+1)&15] * s_BigPrimes[(unsigned)pStr[c] >> 4];
1555 return Key;
1556 }
Vec_IntUniqueLookup(Vec_Int_t * vData,int i,int nIntSize,int * pNexts,int * pStart)1557 static inline int * Vec_IntUniqueLookup( Vec_Int_t * vData, int i, int nIntSize, int * pNexts, int * pStart )
1558 {
1559 int * pData = Vec_IntEntryP( vData, i*nIntSize );
1560 for ( ; *pStart != -1; pStart = pNexts + *pStart )
1561 if ( !memcmp( pData, Vec_IntEntryP(vData, *pStart*nIntSize), sizeof(int) * (size_t)nIntSize ) )
1562 return pStart;
1563 return pStart;
1564 }
Vec_IntUniqueCount(Vec_Int_t * vData,int nIntSize,Vec_Int_t ** pvMap)1565 static inline int Vec_IntUniqueCount( Vec_Int_t * vData, int nIntSize, Vec_Int_t ** pvMap )
1566 {
1567 int nEntries = Vec_IntSize(vData) / nIntSize;
1568 int TableMask = (1 << Abc_Base2Log(nEntries)) - 1;
1569 int * pTable = ABC_FALLOC( int, TableMask+1 );
1570 int * pNexts = ABC_FALLOC( int, TableMask+1 );
1571 int * pClass = ABC_ALLOC( int, nEntries );
1572 int i, Key, * pEnt, nUnique = 0;
1573 assert( nEntries * nIntSize == Vec_IntSize(vData) );
1574 for ( i = 0; i < nEntries; i++ )
1575 {
1576 pEnt = Vec_IntEntryP( vData, i*nIntSize );
1577 Key = TableMask & Vec_IntUniqueHashKey( (unsigned char *)pEnt, 4*nIntSize );
1578 pEnt = Vec_IntUniqueLookup( vData, i, nIntSize, pNexts, pTable+Key );
1579 if ( *pEnt == -1 )
1580 *pEnt = i, nUnique++;
1581 pClass[i] = *pEnt;
1582 }
1583 // Vec_IntUniqueProfile( vData, pTable, pNexts, TableMask, nIntSize );
1584 ABC_FREE( pTable );
1585 ABC_FREE( pNexts );
1586 if ( pvMap )
1587 *pvMap = Vec_IntAllocArray( pClass, nEntries );
1588 else
1589 ABC_FREE( pClass );
1590 return nUnique;
1591 }
Vec_IntUniqifyHash(Vec_Int_t * vData,int nIntSize)1592 static inline Vec_Int_t * Vec_IntUniqifyHash( Vec_Int_t * vData, int nIntSize )
1593 {
1594 Vec_Int_t * vMap, * vUnique;
1595 int i, Ent, nUnique = Vec_IntUniqueCount( vData, nIntSize, &vMap );
1596 vUnique = Vec_IntAlloc( nUnique * nIntSize );
1597 Vec_IntForEachEntry( vMap, Ent, i )
1598 {
1599 if ( Ent < i ) continue;
1600 assert( Ent == i );
1601 Vec_IntPushArray( vUnique, Vec_IntEntryP(vData, i*nIntSize), nIntSize );
1602 }
1603 assert( Vec_IntSize(vUnique) == nUnique * nIntSize );
1604 Vec_IntFree( vMap );
1605 return vUnique;
1606 }
1607
1608 /**Function*************************************************************
1609
1610 Synopsis [Comparison procedure for two integers.]
1611
1612 Description []
1613
1614 SideEffects []
1615
1616 SeeAlso []
1617
1618 ***********************************************************************/
Vec_IntSortCompareUnsigned(unsigned * pp1,unsigned * pp2)1619 static inline int Vec_IntSortCompareUnsigned( unsigned * pp1, unsigned * pp2 )
1620 {
1621 if ( *pp1 < *pp2 )
1622 return -1;
1623 if ( *pp1 > *pp2 )
1624 return 1;
1625 return 0;
1626 }
1627
1628 /**Function*************************************************************
1629
1630 Synopsis [Sorting the entries by their integer value.]
1631
1632 Description []
1633
1634 SideEffects []
1635
1636 SeeAlso []
1637
1638 ***********************************************************************/
Vec_IntSortUnsigned(Vec_Int_t * p)1639 static inline void Vec_IntSortUnsigned( Vec_Int_t * p )
1640 {
1641 qsort( (void *)p->pArray, (size_t)p->nSize, sizeof(int),
1642 (int (*)(const void *, const void *)) Vec_IntSortCompareUnsigned );
1643 }
1644
1645 /**Function*************************************************************
1646
1647 Synopsis [Returns the number of common entries.]
1648
1649 Description [Assumes that the vectors are sorted in the increasing order.]
1650
1651 SideEffects []
1652
1653 SeeAlso []
1654
1655 ***********************************************************************/
Vec_IntTwoCountCommon(Vec_Int_t * vArr1,Vec_Int_t * vArr2)1656 static inline int Vec_IntTwoCountCommon( Vec_Int_t * vArr1, Vec_Int_t * vArr2 )
1657 {
1658 int * pBeg1 = vArr1->pArray;
1659 int * pBeg2 = vArr2->pArray;
1660 int * pEnd1 = vArr1->pArray + vArr1->nSize;
1661 int * pEnd2 = vArr2->pArray + vArr2->nSize;
1662 int Counter = 0;
1663 while ( pBeg1 < pEnd1 && pBeg2 < pEnd2 )
1664 {
1665 if ( *pBeg1 == *pBeg2 )
1666 pBeg1++, pBeg2++, Counter++;
1667 else if ( *pBeg1 < *pBeg2 )
1668 pBeg1++;
1669 else
1670 pBeg2++;
1671 }
1672 return Counter;
1673 }
1674
1675 /**Function*************************************************************
1676
1677 Synopsis [Collects common entries.]
1678
1679 Description [Assumes that the vectors are sorted in the increasing order.]
1680
1681 SideEffects []
1682
1683 SeeAlso []
1684
1685 ***********************************************************************/
Vec_IntTwoFindCommon(Vec_Int_t * vArr1,Vec_Int_t * vArr2,Vec_Int_t * vArr)1686 static inline int Vec_IntTwoFindCommon( Vec_Int_t * vArr1, Vec_Int_t * vArr2, Vec_Int_t * vArr )
1687 {
1688 int * pBeg1 = vArr1->pArray;
1689 int * pBeg2 = vArr2->pArray;
1690 int * pEnd1 = vArr1->pArray + vArr1->nSize;
1691 int * pEnd2 = vArr2->pArray + vArr2->nSize;
1692 Vec_IntClear( vArr );
1693 while ( pBeg1 < pEnd1 && pBeg2 < pEnd2 )
1694 {
1695 if ( *pBeg1 == *pBeg2 )
1696 Vec_IntPush( vArr, *pBeg1 ), pBeg1++, pBeg2++;
1697 else if ( *pBeg1 < *pBeg2 )
1698 pBeg1++;
1699 else
1700 pBeg2++;
1701 }
1702 return Vec_IntSize(vArr);
1703 }
Vec_IntTwoFindCommonReverse(Vec_Int_t * vArr1,Vec_Int_t * vArr2,Vec_Int_t * vArr)1704 static inline int Vec_IntTwoFindCommonReverse( Vec_Int_t * vArr1, Vec_Int_t * vArr2, Vec_Int_t * vArr )
1705 {
1706 int * pBeg1 = vArr1->pArray;
1707 int * pBeg2 = vArr2->pArray;
1708 int * pEnd1 = vArr1->pArray + vArr1->nSize;
1709 int * pEnd2 = vArr2->pArray + vArr2->nSize;
1710 Vec_IntClear( vArr );
1711 while ( pBeg1 < pEnd1 && pBeg2 < pEnd2 )
1712 {
1713 if ( *pBeg1 == *pBeg2 )
1714 Vec_IntPush( vArr, *pBeg1 ), pBeg1++, pBeg2++;
1715 else if ( *pBeg1 > *pBeg2 )
1716 pBeg1++;
1717 else
1718 pBeg2++;
1719 }
1720 return Vec_IntSize(vArr);
1721 }
1722
1723 /**Function*************************************************************
1724
1725 Synopsis [Collects and removes common entries]
1726
1727 Description [Assumes that the vectors are sorted in the increasing order.]
1728
1729 SideEffects []
1730
1731 SeeAlso []
1732
1733 ***********************************************************************/
Vec_IntTwoRemoveCommon(Vec_Int_t * vArr1,Vec_Int_t * vArr2,Vec_Int_t * vArr)1734 static inline int Vec_IntTwoRemoveCommon( Vec_Int_t * vArr1, Vec_Int_t * vArr2, Vec_Int_t * vArr )
1735 {
1736 int * pBeg1 = vArr1->pArray;
1737 int * pBeg2 = vArr2->pArray;
1738 int * pEnd1 = vArr1->pArray + vArr1->nSize;
1739 int * pEnd2 = vArr2->pArray + vArr2->nSize;
1740 int * pBeg1New = vArr1->pArray;
1741 int * pBeg2New = vArr2->pArray;
1742 Vec_IntClear( vArr );
1743 while ( pBeg1 < pEnd1 && pBeg2 < pEnd2 )
1744 {
1745 if ( *pBeg1 == *pBeg2 )
1746 Vec_IntPush( vArr, *pBeg1 ), pBeg1++, pBeg2++;
1747 else if ( *pBeg1 < *pBeg2 )
1748 *pBeg1New++ = *pBeg1++;
1749 else
1750 *pBeg2New++ = *pBeg2++;
1751 }
1752 while ( pBeg1 < pEnd1 )
1753 *pBeg1New++ = *pBeg1++;
1754 while ( pBeg2 < pEnd2 )
1755 *pBeg2New++ = *pBeg2++;
1756 Vec_IntShrink( vArr1, pBeg1New - vArr1->pArray );
1757 Vec_IntShrink( vArr2, pBeg2New - vArr2->pArray );
1758 return Vec_IntSize(vArr);
1759 }
1760
1761 /**Function*************************************************************
1762
1763 Synopsis [Removes entries of the second one from the first one.]
1764
1765 Description [Assumes that the vectors are sorted in the increasing order.]
1766
1767 SideEffects []
1768
1769 SeeAlso []
1770
1771 ***********************************************************************/
Vec_IntTwoRemove(Vec_Int_t * vArr1,Vec_Int_t * vArr2)1772 static inline int Vec_IntTwoRemove( Vec_Int_t * vArr1, Vec_Int_t * vArr2 )
1773 {
1774 int * pBeg1 = vArr1->pArray;
1775 int * pBeg2 = vArr2->pArray;
1776 int * pEnd1 = vArr1->pArray + vArr1->nSize;
1777 int * pEnd2 = vArr2->pArray + vArr2->nSize;
1778 int * pBeg1New = vArr1->pArray;
1779 while ( pBeg1 < pEnd1 && pBeg2 < pEnd2 )
1780 {
1781 if ( *pBeg1 == *pBeg2 )
1782 pBeg1++, pBeg2++;
1783 else if ( *pBeg1 < *pBeg2 )
1784 *pBeg1New++ = *pBeg1++;
1785 else
1786 pBeg2++;
1787 }
1788 while ( pBeg1 < pEnd1 )
1789 *pBeg1New++ = *pBeg1++;
1790 Vec_IntShrink( vArr1, pBeg1New - vArr1->pArray );
1791 return Vec_IntSize(vArr1);
1792 }
1793
1794 /**Function*************************************************************
1795
1796 Synopsis [Returns the result of merging the two vectors.]
1797
1798 Description [Assumes that the vectors are sorted in the increasing order.]
1799
1800 SideEffects []
1801
1802 SeeAlso []
1803
1804 ***********************************************************************/
Vec_IntTwoMerge2Int(Vec_Int_t * vArr1,Vec_Int_t * vArr2,Vec_Int_t * vArr)1805 static inline void Vec_IntTwoMerge2Int( Vec_Int_t * vArr1, Vec_Int_t * vArr2, Vec_Int_t * vArr )
1806 {
1807 int * pBeg = vArr->pArray;
1808 int * pBeg1 = vArr1->pArray;
1809 int * pBeg2 = vArr2->pArray;
1810 int * pEnd1 = vArr1->pArray + vArr1->nSize;
1811 int * pEnd2 = vArr2->pArray + vArr2->nSize;
1812 while ( pBeg1 < pEnd1 && pBeg2 < pEnd2 )
1813 {
1814 if ( *pBeg1 == *pBeg2 )
1815 *pBeg++ = *pBeg1++, pBeg2++;
1816 else if ( *pBeg1 < *pBeg2 )
1817 *pBeg++ = *pBeg1++;
1818 else
1819 *pBeg++ = *pBeg2++;
1820 }
1821 while ( pBeg1 < pEnd1 )
1822 *pBeg++ = *pBeg1++;
1823 while ( pBeg2 < pEnd2 )
1824 *pBeg++ = *pBeg2++;
1825 vArr->nSize = pBeg - vArr->pArray;
1826 assert( vArr->nSize <= vArr->nCap );
1827 assert( vArr->nSize >= vArr1->nSize );
1828 assert( vArr->nSize >= vArr2->nSize );
1829 }
Vec_IntTwoMerge(Vec_Int_t * vArr1,Vec_Int_t * vArr2)1830 static inline Vec_Int_t * Vec_IntTwoMerge( Vec_Int_t * vArr1, Vec_Int_t * vArr2 )
1831 {
1832 Vec_Int_t * vArr = Vec_IntAlloc( vArr1->nSize + vArr2->nSize );
1833 Vec_IntTwoMerge2Int( vArr1, vArr2, vArr );
1834 return vArr;
1835 }
Vec_IntTwoMerge2(Vec_Int_t * vArr1,Vec_Int_t * vArr2,Vec_Int_t * vArr)1836 static inline void Vec_IntTwoMerge2( Vec_Int_t * vArr1, Vec_Int_t * vArr2, Vec_Int_t * vArr )
1837 {
1838 Vec_IntGrow( vArr, Vec_IntSize(vArr1) + Vec_IntSize(vArr2) );
1839 Vec_IntTwoMerge2Int( vArr1, vArr2, vArr );
1840 }
1841
1842 /**Function*************************************************************
1843
1844 Synopsis [Returns the result of splitting of the two vectors.]
1845
1846 Description [Assumes that the vectors are sorted in the increasing order.]
1847
1848 SideEffects []
1849
1850 SeeAlso []
1851
1852 ***********************************************************************/
Vec_IntTwoSplit(Vec_Int_t * vArr1,Vec_Int_t * vArr2,Vec_Int_t * vArr,Vec_Int_t * vArr1n,Vec_Int_t * vArr2n)1853 static inline void Vec_IntTwoSplit( Vec_Int_t * vArr1, Vec_Int_t * vArr2, Vec_Int_t * vArr, Vec_Int_t * vArr1n, Vec_Int_t * vArr2n )
1854 {
1855 int * pBeg1 = vArr1->pArray;
1856 int * pBeg2 = vArr2->pArray;
1857 int * pEnd1 = vArr1->pArray + vArr1->nSize;
1858 int * pEnd2 = vArr2->pArray + vArr2->nSize;
1859 while ( pBeg1 < pEnd1 && pBeg2 < pEnd2 )
1860 {
1861 if ( *pBeg1 == *pBeg2 )
1862 Vec_IntPush( vArr, *pBeg1++ ), pBeg2++;
1863 else if ( *pBeg1 < *pBeg2 )
1864 Vec_IntPush( vArr1n, *pBeg1++ );
1865 else
1866 Vec_IntPush( vArr2n, *pBeg2++ );
1867 }
1868 while ( pBeg1 < pEnd1 )
1869 Vec_IntPush( vArr1n, *pBeg1++ );
1870 while ( pBeg2 < pEnd2 )
1871 Vec_IntPush( vArr2n, *pBeg2++ );
1872 }
1873
1874
1875 /**Function*************************************************************
1876
1877 Synopsis []
1878
1879 Description []
1880
1881 SideEffects []
1882
1883 SeeAlso []
1884
1885 ***********************************************************************/
Vec_IntSelectSort(int * pArray,int nSize)1886 static inline void Vec_IntSelectSort( int * pArray, int nSize )
1887 {
1888 int temp, i, j, best_i;
1889 for ( i = 0; i < nSize-1; i++ )
1890 {
1891 best_i = i;
1892 for ( j = i+1; j < nSize; j++ )
1893 if ( pArray[j] < pArray[best_i] )
1894 best_i = j;
1895 temp = pArray[i];
1896 pArray[i] = pArray[best_i];
1897 pArray[best_i] = temp;
1898 }
1899 }
Vec_IntSelectSortReverse(int * pArray,int nSize)1900 static inline void Vec_IntSelectSortReverse( int * pArray, int nSize )
1901 {
1902 int temp, i, j, best_i;
1903 for ( i = 0; i < nSize-1; i++ )
1904 {
1905 best_i = i;
1906 for ( j = i+1; j < nSize; j++ )
1907 if ( pArray[j] > pArray[best_i] )
1908 best_i = j;
1909 temp = pArray[i];
1910 pArray[i] = pArray[best_i];
1911 pArray[best_i] = temp;
1912 }
1913 }
1914
1915 /**Function*************************************************************
1916
1917 Synopsis []
1918
1919 Description []
1920
1921 SideEffects []
1922
1923 SeeAlso []
1924
1925 ***********************************************************************/
Vec_IntSelectSortCost(int * pArray,int nSize,Vec_Int_t * vCosts)1926 static inline void Vec_IntSelectSortCost( int * pArray, int nSize, Vec_Int_t * vCosts )
1927 {
1928 int i, j, best_i;
1929 for ( i = 0; i < nSize-1; i++ )
1930 {
1931 best_i = i;
1932 for ( j = i+1; j < nSize; j++ )
1933 if ( Vec_IntEntry(vCosts, pArray[j]) < Vec_IntEntry(vCosts, pArray[best_i]) )
1934 best_i = j;
1935 ABC_SWAP( int, pArray[i], pArray[best_i] );
1936 }
1937 }
Vec_IntSelectSortCostReverse(int * pArray,int nSize,Vec_Int_t * vCosts)1938 static inline void Vec_IntSelectSortCostReverse( int * pArray, int nSize, Vec_Int_t * vCosts )
1939 {
1940 int i, j, best_i;
1941 for ( i = 0; i < nSize-1; i++ )
1942 {
1943 best_i = i;
1944 for ( j = i+1; j < nSize; j++ )
1945 if ( Vec_IntEntry(vCosts, pArray[j]) > Vec_IntEntry(vCosts, pArray[best_i]) )
1946 best_i = j;
1947 ABC_SWAP( int, pArray[i], pArray[best_i] );
1948 }
1949 }
1950
Vec_IntSelectSortCost2(int * pArray,int nSize,int * pCosts)1951 static inline void Vec_IntSelectSortCost2( int * pArray, int nSize, int * pCosts )
1952 {
1953 int i, j, best_i;
1954 for ( i = 0; i < nSize-1; i++ )
1955 {
1956 best_i = i;
1957 for ( j = i+1; j < nSize; j++ )
1958 if ( pCosts[j] < pCosts[best_i] )
1959 best_i = j;
1960 ABC_SWAP( int, pArray[i], pArray[best_i] );
1961 ABC_SWAP( int, pCosts[i], pCosts[best_i] );
1962 }
1963 }
Vec_IntSelectSortCost2Reverse(int * pArray,int nSize,int * pCosts)1964 static inline void Vec_IntSelectSortCost2Reverse( int * pArray, int nSize, int * pCosts )
1965 {
1966 int i, j, best_i;
1967 for ( i = 0; i < nSize-1; i++ )
1968 {
1969 best_i = i;
1970 for ( j = i+1; j < nSize; j++ )
1971 if ( pCosts[j] > pCosts[best_i] )
1972 best_i = j;
1973 ABC_SWAP( int, pArray[i], pArray[best_i] );
1974 ABC_SWAP( int, pCosts[i], pCosts[best_i] );
1975 }
1976 }
1977
1978 /**Function*************************************************************
1979
1980 Synopsis []
1981
1982 Description []
1983
1984 SideEffects []
1985
1986 SeeAlso []
1987
1988 ***********************************************************************/
Vec_IntPrint(Vec_Int_t * vVec)1989 static inline void Vec_IntPrint( Vec_Int_t * vVec )
1990 {
1991 int i, Entry;
1992 printf( "Vector has %d entries: {", Vec_IntSize(vVec) );
1993 Vec_IntForEachEntry( vVec, Entry, i )
1994 printf( " %d", Entry );
1995 printf( " }\n" );
1996 }
Vec_IntPrintBinary(Vec_Int_t * vVec)1997 static inline void Vec_IntPrintBinary( Vec_Int_t * vVec )
1998 {
1999 int i, Entry;
2000 Vec_IntForEachEntry( vVec, Entry, i )
2001 printf( "%d", (int)(Entry != 0) );
2002 }
2003
2004 /**Function*************************************************************
2005
2006 Synopsis []
2007
2008 Description []
2009
2010 SideEffects []
2011
2012 SeeAlso []
2013
2014 ***********************************************************************/
Vec_IntCompareVec(Vec_Int_t * p1,Vec_Int_t * p2)2015 static inline int Vec_IntCompareVec( Vec_Int_t * p1, Vec_Int_t * p2 )
2016 {
2017 if ( p1 == NULL || p2 == NULL )
2018 return (p1 != NULL) - (p2 != NULL);
2019 if ( Vec_IntSize(p1) != Vec_IntSize(p2) )
2020 return Vec_IntSize(p1) - Vec_IntSize(p2);
2021 return memcmp( Vec_IntArray(p1), Vec_IntArray(p2), sizeof(int)*(size_t)Vec_IntSize(p1) );
2022 }
2023
2024 /**Function*************************************************************
2025
2026 Synopsis [Appends the contents of the second vector.]
2027
2028 Description []
2029
2030 SideEffects []
2031
2032 SeeAlso []
2033
2034 ***********************************************************************/
Vec_IntAppend(Vec_Int_t * vVec1,Vec_Int_t * vVec2)2035 static inline void Vec_IntAppend( Vec_Int_t * vVec1, Vec_Int_t * vVec2 )
2036 {
2037 int Entry, i;
2038 Vec_IntForEachEntry( vVec2, Entry, i )
2039 Vec_IntPush( vVec1, Entry );
2040 }
Vec_IntAppendSkip(Vec_Int_t * vVec1,Vec_Int_t * vVec2,int iVar)2041 static inline void Vec_IntAppendSkip( Vec_Int_t * vVec1, Vec_Int_t * vVec2, int iVar )
2042 {
2043 int Entry, i;
2044 Vec_IntForEachEntry( vVec2, Entry, i )
2045 if ( i != iVar )
2046 Vec_IntPush( vVec1, Entry );
2047 }
Vec_IntAppendMinus(Vec_Int_t * vVec1,Vec_Int_t * vVec2,int fMinus)2048 static inline void Vec_IntAppendMinus( Vec_Int_t * vVec1, Vec_Int_t * vVec2, int fMinus )
2049 {
2050 int Entry, i;
2051 Vec_IntClear( vVec1 );
2052 Vec_IntForEachEntry( vVec2, Entry, i )
2053 Vec_IntPush( vVec1, fMinus ? -Entry : Entry );
2054 }
2055
2056 /**Function*************************************************************
2057
2058 Synopsis [Remapping attributes after objects were duplicated.]
2059
2060 Description []
2061
2062 SideEffects []
2063
2064 SeeAlso []
2065
2066 ***********************************************************************/
Vec_IntRemapArray(Vec_Int_t * vOld2New,Vec_Int_t * vOld,Vec_Int_t * vNew,int nNew)2067 static inline void Vec_IntRemapArray( Vec_Int_t * vOld2New, Vec_Int_t * vOld, Vec_Int_t * vNew, int nNew )
2068 {
2069 int iOld, iNew;
2070 if ( Vec_IntSize(vOld) == 0 )
2071 return;
2072 Vec_IntFill( vNew, nNew, 0 );
2073 Vec_IntForEachEntry( vOld2New, iNew, iOld )
2074 if ( iNew > 0 && iNew < nNew && iOld < Vec_IntSize(vOld) && Vec_IntEntry(vOld, iOld) != 0 )
2075 Vec_IntWriteEntry( vNew, iNew, Vec_IntEntry(vOld, iOld) );
2076 }
2077
2078 ABC_NAMESPACE_HEADER_END
2079
2080 #endif
2081
2082 ////////////////////////////////////////////////////////////////////////
2083 /// END OF FILE ///
2084 ////////////////////////////////////////////////////////////////////////
2085
2086