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