abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
vecWrd.h
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [vecWrd.h]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Resizable arrays.]
8 
9  Synopsis [Resizable arrays of long unsigned 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: vecWrd.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #ifndef ABC__misc__vec__vecWrd_h
22 #define ABC__misc__vec__vecWrd_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_Wrd_t_ Vec_Wrd_t;
43 struct Vec_Wrd_t_
44 {
45  int nCap;
46  int nSize;
48 };
49 
50 ////////////////////////////////////////////////////////////////////////
51 /// MACRO DEFINITIONS ///
52 ////////////////////////////////////////////////////////////////////////
53 
54 #define Vec_WrdForEachEntry( vVec, Entry, i ) \
55  for ( i = 0; (i < Vec_WrdSize(vVec)) && (((Entry) = Vec_WrdEntry(vVec, i)), 1); i++ )
56 #define Vec_WrdForEachEntryStart( vVec, Entry, i, Start ) \
57  for ( i = Start; (i < Vec_WrdSize(vVec)) && (((Entry) = Vec_WrdEntry(vVec, i)), 1); i++ )
58 #define Vec_WrdForEachEntryStop( vVec, Entry, i, Stop ) \
59  for ( i = 0; (i < Stop) && (((Entry) = Vec_WrdEntry(vVec, i)), 1); i++ )
60 #define Vec_WrdForEachEntryStartStop( vVec, Entry, i, Start, Stop ) \
61  for ( i = Start; (i < Stop) && (((Entry) = Vec_WrdEntry(vVec, i)), 1); i++ )
62 #define Vec_WrdForEachEntryReverse( vVec, pEntry, i ) \
63  for ( i = Vec_WrdSize(vVec) - 1; (i >= 0) && (((pEntry) = Vec_WrdEntry(vVec, i)), 1); i-- )
64 
65 ////////////////////////////////////////////////////////////////////////
66 /// FUNCTION DEFINITIONS ///
67 ////////////////////////////////////////////////////////////////////////
68 
69 /**Function*************************************************************
70 
71  Synopsis [Allocates a vector with the given capacity.]
72 
73  Description []
74 
75  SideEffects []
76 
77  SeeAlso []
78 
79 ***********************************************************************/
80 static inline Vec_Wrd_t * Vec_WrdAlloc( int nCap )
81 {
82  Vec_Wrd_t * p;
83  p = ABC_ALLOC( Vec_Wrd_t, 1 );
84  if ( nCap > 0 && nCap < 16 )
85  nCap = 16;
86  p->nSize = 0;
87  p->nCap = nCap;
88  p->pArray = p->nCap? ABC_ALLOC( word, p->nCap ) : NULL;
89  return p;
90 }
91 
92 /**Function*************************************************************
93 
94  Synopsis [Allocates a vector with the given size and cleans it.]
95 
96  Description []
97 
98  SideEffects []
99 
100  SeeAlso []
101 
102 ***********************************************************************/
103 static inline Vec_Wrd_t * Vec_WrdStart( int nSize )
104 {
105  Vec_Wrd_t * p;
106  p = Vec_WrdAlloc( nSize );
107  p->nSize = nSize;
108  memset( p->pArray, 0, sizeof(word) * nSize );
109  return p;
110 }
111 
112 /**Function*************************************************************
113 
114  Synopsis [Allocates a vector with the given size and cleans it.]
115 
116  Description []
117 
118  SideEffects []
119 
120  SeeAlso []
121 
122 ***********************************************************************/
123 static inline Vec_Wrd_t * Vec_WrdStartFull( int nSize )
124 {
125  Vec_Wrd_t * p;
126  p = Vec_WrdAlloc( nSize );
127  p->nSize = nSize;
128  memset( p->pArray, 0xff, sizeof(word) * nSize );
129  return p;
130 }
131 
132 /**Function*************************************************************
133 
134  Synopsis [Allocates a vector with the given size and cleans it.]
135 
136  Description []
137 
138  SideEffects []
139 
140  SeeAlso []
141 
142 ***********************************************************************/
143 static inline Vec_Wrd_t * Vec_WrdStartNatural( int nSize )
144 {
145  Vec_Wrd_t * p;
146  int i;
147  p = Vec_WrdAlloc( nSize );
148  p->nSize = nSize;
149  for ( i = 0; i < nSize; i++ )
150  p->pArray[i] = i;
151  return p;
152 }
153 
154 /**Function*************************************************************
155 
156  Synopsis [Creates the vector from an integer array of the given size.]
157 
158  Description []
159 
160  SideEffects []
161 
162  SeeAlso []
163 
164 ***********************************************************************/
165 static inline Vec_Wrd_t * Vec_WrdAllocArray( word * pArray, int nSize )
166 {
167  Vec_Wrd_t * p;
168  p = ABC_ALLOC( Vec_Wrd_t, 1 );
169  p->nSize = nSize;
170  p->nCap = nSize;
171  p->pArray = pArray;
172  return p;
173 }
174 
175 /**Function*************************************************************
176 
177  Synopsis [Creates the vector from an integer array of the given size.]
178 
179  Description []
180 
181  SideEffects []
182 
183  SeeAlso []
184 
185 ***********************************************************************/
186 static inline Vec_Wrd_t * Vec_WrdAllocArrayCopy( word * pArray, int nSize )
187 {
188  Vec_Wrd_t * p;
189  p = ABC_ALLOC( Vec_Wrd_t, 1 );
190  p->nSize = nSize;
191  p->nCap = nSize;
192  p->pArray = ABC_ALLOC( word, nSize );
193  memcpy( p->pArray, pArray, sizeof(word) * nSize );
194  return p;
195 }
196 
197 /**Function*************************************************************
198 
199  Synopsis [Duplicates the integer array.]
200 
201  Description []
202 
203  SideEffects []
204 
205  SeeAlso []
206 
207 ***********************************************************************/
208 static inline Vec_Wrd_t * Vec_WrdDup( Vec_Wrd_t * pVec )
209 {
210  Vec_Wrd_t * p;
211  p = ABC_ALLOC( Vec_Wrd_t, 1 );
212  p->nSize = pVec->nSize;
213  p->nCap = pVec->nSize;
214  p->pArray = p->nCap? ABC_ALLOC( word, p->nCap ) : NULL;
215  memcpy( p->pArray, pVec->pArray, sizeof(word) * pVec->nSize );
216  return p;
217 }
218 
219 /**Function*************************************************************
220 
221  Synopsis [Transfers the array into another vector.]
222 
223  Description []
224 
225  SideEffects []
226 
227  SeeAlso []
228 
229 ***********************************************************************/
230 static inline Vec_Wrd_t * Vec_WrdDupArray( Vec_Wrd_t * pVec )
231 {
232  Vec_Wrd_t * p;
233  p = ABC_ALLOC( Vec_Wrd_t, 1 );
234  p->nSize = pVec->nSize;
235  p->nCap = pVec->nCap;
236  p->pArray = pVec->pArray;
237  pVec->nSize = 0;
238  pVec->nCap = 0;
239  pVec->pArray = NULL;
240  return p;
241 }
242 
243 /**Function*************************************************************
244 
245  Synopsis []
246 
247  Description []
248 
249  SideEffects []
250 
251  SeeAlso []
252 
253 ***********************************************************************/
254 static inline void Vec_WrdErase( Vec_Wrd_t * p )
255 {
256  ABC_FREE( p->pArray );
257  p->nSize = 0;
258  p->nCap = 0;
259 }
260 static inline void Vec_WrdFree( Vec_Wrd_t * p )
261 {
262  ABC_FREE( p->pArray );
263  ABC_FREE( p );
264 }
265 
266 /**Function*************************************************************
267 
268  Synopsis []
269 
270  Description []
271 
272  SideEffects []
273 
274  SeeAlso []
275 
276 ***********************************************************************/
277 static inline void Vec_WrdFreeP( Vec_Wrd_t ** p )
278 {
279  if ( *p == NULL )
280  return;
281  ABC_FREE( (*p)->pArray );
282  ABC_FREE( (*p) );
283 }
284 
285 /**Function*************************************************************
286 
287  Synopsis []
288 
289  Description []
290 
291  SideEffects []
292 
293  SeeAlso []
294 
295 ***********************************************************************/
296 static inline word * Vec_WrdReleaseArray( Vec_Wrd_t * p )
297 {
298  word * pArray = p->pArray;
299  p->nCap = 0;
300  p->nSize = 0;
301  p->pArray = NULL;
302  return pArray;
303 }
304 
305 /**Function*************************************************************
306 
307  Synopsis []
308 
309  Description []
310 
311  SideEffects []
312 
313  SeeAlso []
314 
315 ***********************************************************************/
316 static inline word * Vec_WrdArray( Vec_Wrd_t * p )
317 {
318  return p->pArray;
319 }
320 static inline word * Vec_WrdLimit( Vec_Wrd_t * p )
321 {
322  return p->pArray + p->nSize;
323 }
324 
325 /**Function*************************************************************
326 
327  Synopsis []
328 
329  Description []
330 
331  SideEffects []
332 
333  SeeAlso []
334 
335 ***********************************************************************/
336 static inline int Vec_WrdSize( Vec_Wrd_t * p )
337 {
338  return 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_WrdCap( Vec_Wrd_t * p )
353 {
354  return p->nCap;
355 }
356 
357 /**Function*************************************************************
358 
359  Synopsis []
360 
361  Description []
362 
363  SideEffects []
364 
365  SeeAlso []
366 
367 ***********************************************************************/
368 static inline double Vec_WrdMemory( Vec_Wrd_t * p )
369 {
370  return !p ? 0.0 : 1.0 * sizeof(word) * p->nCap + sizeof(Vec_Wrd_t);
371 }
372 
373 /**Function*************************************************************
374 
375  Synopsis []
376 
377  Description []
378 
379  SideEffects []
380 
381  SeeAlso []
382 
383 ***********************************************************************/
384 static inline word Vec_WrdEntry( Vec_Wrd_t * p, int i )
385 {
386  assert( i >= 0 && i < p->nSize );
387  return p->pArray[i];
388 }
389 
390 /**Function*************************************************************
391 
392  Synopsis []
393 
394  Description []
395 
396  SideEffects []
397 
398  SeeAlso []
399 
400 ***********************************************************************/
401 static inline word * Vec_WrdEntryP( Vec_Wrd_t * p, int i )
402 {
403  assert( i >= 0 && i < p->nSize );
404  return p->pArray + i;
405 }
406 
407 /**Function*************************************************************
408 
409  Synopsis []
410 
411  Description []
412 
413  SideEffects []
414 
415  SeeAlso []
416 
417 ***********************************************************************/
418 static inline void Vec_WrdWriteEntry( Vec_Wrd_t * p, int i, word Entry )
419 {
420  assert( i >= 0 && i < p->nSize );
421  p->pArray[i] = Entry;
422 }
423 
424 /**Function*************************************************************
425 
426  Synopsis []
427 
428  Description []
429 
430  SideEffects []
431 
432  SeeAlso []
433 
434 ***********************************************************************/
435 static inline word Vec_WrdAddToEntry( Vec_Wrd_t * p, int i, word Addition )
436 {
437  assert( i >= 0 && i < p->nSize );
438  return p->pArray[i] += Addition;
439 }
440 
441 /**Function*************************************************************
442 
443  Synopsis []
444 
445  Description []
446 
447  SideEffects []
448 
449  SeeAlso []
450 
451 ***********************************************************************/
452 static inline word Vec_WrdEntryLast( Vec_Wrd_t * p )
453 {
454  assert( p->nSize > 0 );
455  return p->pArray[p->nSize-1];
456 }
457 
458 /**Function*************************************************************
459 
460  Synopsis [Resizes the vector to the given capacity.]
461 
462  Description []
463 
464  SideEffects []
465 
466  SeeAlso []
467 
468 ***********************************************************************/
469 static inline void Vec_WrdGrow( Vec_Wrd_t * p, int nCapMin )
470 {
471  if ( p->nCap >= nCapMin )
472  return;
473  p->pArray = ABC_REALLOC( word, p->pArray, nCapMin );
474  assert( p->pArray );
475  p->nCap = nCapMin;
476 }
477 
478 /**Function*************************************************************
479 
480  Synopsis [Fills the vector with given number of entries.]
481 
482  Description []
483 
484  SideEffects []
485 
486  SeeAlso []
487 
488 ***********************************************************************/
489 static inline void Vec_WrdFill( Vec_Wrd_t * p, int nSize, word Fill )
490 {
491  int i;
492  Vec_WrdGrow( p, nSize );
493  for ( i = 0; i < nSize; i++ )
494  p->pArray[i] = Fill;
495  p->nSize = nSize;
496 }
497 
498 /**Function*************************************************************
499 
500  Synopsis [Fills the vector with given number of entries.]
501 
502  Description []
503 
504  SideEffects []
505 
506  SeeAlso []
507 
508 ***********************************************************************/
509 static inline void Vec_WrdFillExtra( Vec_Wrd_t * p, int nSize, word Fill )
510 {
511  int i;
512  if ( nSize <= p->nSize )
513  return;
514  if ( nSize > 2 * p->nCap )
515  Vec_WrdGrow( p, nSize );
516  else if ( nSize > p->nCap )
517  Vec_WrdGrow( p, 2 * p->nCap );
518  for ( i = p->nSize; i < nSize; i++ )
519  p->pArray[i] = Fill;
520  p->nSize = nSize;
521 }
522 
523 /**Function*************************************************************
524 
525  Synopsis [Returns the entry even if the place not exist.]
526 
527  Description []
528 
529  SideEffects []
530 
531  SeeAlso []
532 
533 ***********************************************************************/
534 static inline word Vec_WrdGetEntry( Vec_Wrd_t * p, int i )
535 {
536  Vec_WrdFillExtra( p, i + 1, 0 );
537  return Vec_WrdEntry( p, i );
538 }
539 
540 /**Function*************************************************************
541 
542  Synopsis [Returns the entry even if the place not exist.]
543 
544  Description []
545 
546  SideEffects []
547 
548  SeeAlso []
549 
550 ***********************************************************************/
551 static inline word * Vec_WrdGetEntryP( Vec_Wrd_t * p, int i )
552 {
553  Vec_WrdFillExtra( p, i + 1, 0 );
554  return Vec_WrdEntryP( p, i );
555 }
556 
557 /**Function*************************************************************
558 
559  Synopsis [Inserts the entry even if the place does not exist.]
560 
561  Description []
562 
563  SideEffects []
564 
565  SeeAlso []
566 
567 ***********************************************************************/
568 static inline void Vec_WrdSetEntry( Vec_Wrd_t * p, int i, word Entry )
569 {
570  Vec_WrdFillExtra( p, i + 1, 0 );
571  Vec_WrdWriteEntry( p, i, Entry );
572 }
573 
574 /**Function*************************************************************
575 
576  Synopsis []
577 
578  Description []
579 
580  SideEffects []
581 
582  SeeAlso []
583 
584 ***********************************************************************/
585 static inline void Vec_WrdShrink( Vec_Wrd_t * p, int nSizeNew )
586 {
587  assert( p->nSize >= nSizeNew );
588  p->nSize = nSizeNew;
589 }
590 
591 /**Function*************************************************************
592 
593  Synopsis []
594 
595  Description []
596 
597  SideEffects []
598 
599  SeeAlso []
600 
601 ***********************************************************************/
602 static inline void Vec_WrdClear( Vec_Wrd_t * p )
603 {
604  p->nSize = 0;
605 }
606 
607 /**Function*************************************************************
608 
609  Synopsis []
610 
611  Description []
612 
613  SideEffects []
614 
615  SeeAlso []
616 
617 ***********************************************************************/
618 static inline void Vec_WrdPush( Vec_Wrd_t * p, word Entry )
619 {
620  if ( p->nSize == p->nCap )
621  {
622  if ( p->nCap < 16 )
623  Vec_WrdGrow( p, 16 );
624  else
625  Vec_WrdGrow( p, 2 * p->nCap );
626  }
627  p->pArray[p->nSize++] = Entry;
628 }
629 
630 /**Function*************************************************************
631 
632  Synopsis []
633 
634  Description []
635 
636  SideEffects []
637 
638  SeeAlso []
639 
640 ***********************************************************************/
641 static inline void Vec_WrdPushFirst( Vec_Wrd_t * p, word Entry )
642 {
643  int i;
644  if ( p->nSize == p->nCap )
645  {
646  if ( p->nCap < 16 )
647  Vec_WrdGrow( p, 16 );
648  else
649  Vec_WrdGrow( p, 2 * p->nCap );
650  }
651  p->nSize++;
652  for ( i = p->nSize - 1; i >= 1; i-- )
653  p->pArray[i] = p->pArray[i-1];
654  p->pArray[0] = Entry;
655 }
656 
657 /**Function*************************************************************
658 
659  Synopsis [Inserts the entry while preserving the increasing order.]
660 
661  Description []
662 
663  SideEffects []
664 
665  SeeAlso []
666 
667 ***********************************************************************/
668 static inline void Vec_WrdPushOrder( Vec_Wrd_t * p, word Entry )
669 {
670  int i;
671  if ( p->nSize == p->nCap )
672  {
673  if ( p->nCap < 16 )
674  Vec_WrdGrow( p, 16 );
675  else
676  Vec_WrdGrow( p, 2 * p->nCap );
677  }
678  p->nSize++;
679  for ( i = p->nSize-2; i >= 0; i-- )
680  if ( p->pArray[i] > Entry )
681  p->pArray[i+1] = p->pArray[i];
682  else
683  break;
684  p->pArray[i+1] = Entry;
685 }
686 
687 /**Function*************************************************************
688 
689  Synopsis [Inserts the entry while preserving the increasing order.]
690 
691  Description []
692 
693  SideEffects []
694 
695  SeeAlso []
696 
697 ***********************************************************************/
698 static inline int Vec_WrdPushUniqueOrder( Vec_Wrd_t * p, word Entry )
699 {
700  int i;
701  for ( i = 0; i < p->nSize; i++ )
702  if ( p->pArray[i] == Entry )
703  return 1;
704  Vec_WrdPushOrder( p, Entry );
705  return 0;
706 }
707 
708 /**Function*************************************************************
709 
710  Synopsis []
711 
712  Description []
713 
714  SideEffects []
715 
716  SeeAlso []
717 
718 ***********************************************************************/
719 static inline int Vec_WrdPushUnique( Vec_Wrd_t * p, word Entry )
720 {
721  int i;
722  for ( i = 0; i < p->nSize; i++ )
723  if ( p->pArray[i] == Entry )
724  return 1;
725  Vec_WrdPush( p, Entry );
726  return 0;
727 }
728 
729 /**Function*************************************************************
730 
731  Synopsis [Returns the pointer to the next nWords entries in the vector.]
732 
733  Description []
734 
735  SideEffects []
736 
737  SeeAlso []
738 
739 ***********************************************************************/
740 static inline word * Vec_WrdFetch( Vec_Wrd_t * p, int nWords )
741 {
742  if ( nWords == 0 )
743  return NULL;
744  assert( nWords > 0 );
745  p->nSize += nWords;
746  if ( p->nSize > p->nCap )
747  {
748 // Vec_WrdGrow( p, 2 * p->nSize );
749  return NULL;
750  }
751  return p->pArray + p->nSize - nWords;
752 }
753 
754 /**Function*************************************************************
755 
756  Synopsis [Returns the last entry and removes it from the list.]
757 
758  Description []
759 
760  SideEffects []
761 
762  SeeAlso []
763 
764 ***********************************************************************/
765 static inline word Vec_WrdPop( Vec_Wrd_t * p )
766 {
767  assert( p->nSize > 0 );
768  return p->pArray[--p->nSize];
769 }
770 
771 /**Function*************************************************************
772 
773  Synopsis [Find entry.]
774 
775  Description []
776 
777  SideEffects []
778 
779  SeeAlso []
780 
781 ***********************************************************************/
782 static inline int Vec_WrdFind( Vec_Wrd_t * p, word Entry )
783 {
784  int i;
785  for ( i = 0; i < p->nSize; i++ )
786  if ( p->pArray[i] == Entry )
787  return i;
788  return -1;
789 }
790 
791 /**Function*************************************************************
792 
793  Synopsis []
794 
795  Description []
796 
797  SideEffects []
798 
799  SeeAlso []
800 
801 ***********************************************************************/
802 static inline int Vec_WrdRemove( Vec_Wrd_t * p, word Entry )
803 {
804  int i;
805  for ( i = 0; i < p->nSize; i++ )
806  if ( p->pArray[i] == Entry )
807  break;
808  if ( i == p->nSize )
809  return 0;
810  assert( i < p->nSize );
811  for ( i++; i < p->nSize; i++ )
812  p->pArray[i-1] = p->pArray[i];
813  p->nSize--;
814  return 1;
815 }
816 
817 /**Function*************************************************************
818 
819  Synopsis [Interts entry at the index iHere. Shifts other entries.]
820 
821  Description []
822 
823  SideEffects []
824 
825  SeeAlso []
826 
827 ***********************************************************************/
828 static inline void Vec_WrdInsert( Vec_Wrd_t * p, int iHere, word Entry )
829 {
830  int i;
831  assert( iHere >= 0 && iHere < p->nSize );
832  Vec_WrdPush( p, 0 );
833  for ( i = p->nSize - 1; i > iHere; i-- )
834  p->pArray[i] = p->pArray[i-1];
835  p->pArray[i] = Entry;
836 }
837 
838 /**Function*************************************************************
839 
840  Synopsis [Find entry.]
841 
842  Description []
843 
844  SideEffects []
845 
846  SeeAlso []
847 
848 ***********************************************************************/
849 static inline word Vec_WrdFindMax( Vec_Wrd_t * p )
850 {
851  word Best;
852  int i;
853  if ( p->nSize == 0 )
854  return 0;
855  Best = p->pArray[0];
856  for ( i = 1; i < p->nSize; i++ )
857  if ( Best < p->pArray[i] )
858  Best = p->pArray[i];
859  return Best;
860 }
861 
862 /**Function*************************************************************
863 
864  Synopsis [Find entry.]
865 
866  Description []
867 
868  SideEffects []
869 
870  SeeAlso []
871 
872 ***********************************************************************/
873 static inline word Vec_WrdFindMin( Vec_Wrd_t * p )
874 {
875  word Best;
876  int i;
877  if ( p->nSize == 0 )
878  return 0;
879  Best = p->pArray[0];
880  for ( i = 1; i < p->nSize; i++ )
881  if ( Best > p->pArray[i] )
882  Best = p->pArray[i];
883  return Best;
884 }
885 
886 /**Function*************************************************************
887 
888  Synopsis [Reverses the order of entries.]
889 
890  Description []
891 
892  SideEffects []
893 
894  SeeAlso []
895 
896 ***********************************************************************/
897 static inline void Vec_WrdReverseOrder( Vec_Wrd_t * p )
898 {
899  word Temp;
900  int i;
901  for ( i = 0; i < p->nSize/2; i++ )
902  {
903  Temp = p->pArray[i];
904  p->pArray[i] = p->pArray[p->nSize-1-i];
905  p->pArray[p->nSize-1-i] = Temp;
906  }
907 }
908 
909 /**Function*************************************************************
910 
911  Synopsis []
912 
913  Description []
914 
915  SideEffects []
916 
917  SeeAlso []
918 
919 ***********************************************************************/
920 static inline Vec_Wrd_t * Vec_WrdInvert( Vec_Wrd_t * p, word Fill )
921 {
922  int i;
923  word Entry;
924  Vec_Wrd_t * vRes = Vec_WrdAlloc( 0 );
925  Vec_WrdFill( vRes, Vec_WrdFindMax(p) + 1, Fill );
926  Vec_WrdForEachEntry( p, Entry, i )
927  if ( Entry != Fill )
928  Vec_WrdWriteEntry( vRes, Entry, i );
929  return vRes;
930 }
931 
932 /**Function*************************************************************
933 
934  Synopsis []
935 
936  Description []
937 
938  SideEffects []
939 
940  SeeAlso []
941 
942 ***********************************************************************/
943 static inline word Vec_WrdSum( Vec_Wrd_t * p )
944 {
945  word Counter = 0;
946  int i;
947  for ( i = 0; i < p->nSize; i++ )
948  Counter += p->pArray[i];
949  return Counter;
950 }
951 
952 /**Function*************************************************************
953 
954  Synopsis [Checks if two vectors are equal.]
955 
956  Description []
957 
958  SideEffects []
959 
960  SeeAlso []
961 
962 ***********************************************************************/
963 static inline int Vec_WrdEqual( Vec_Wrd_t * p1, Vec_Wrd_t * p2 )
964 {
965  int i;
966  if ( p1->nSize != p2->nSize )
967  return 0;
968  for ( i = 0; i < p1->nSize; i++ )
969  if ( p1->pArray[i] != p2->pArray[i] )
970  return 0;
971  return 1;
972 }
973 
974 /**Function*************************************************************
975 
976  Synopsis [Counts the number of common entries.]
977 
978  Description []
979 
980  SideEffects []
981 
982  SeeAlso []
983 
984 ***********************************************************************/
985 static inline int Vec_WrdCountCommon( Vec_Wrd_t * p1, Vec_Wrd_t * p2 )
986 {
987  Vec_Wrd_t * vTemp;
988  word Entry;
989  int i, Counter = 0;
990  if ( Vec_WrdSize(p1) < Vec_WrdSize(p2) )
991  vTemp = p1, p1 = p2, p2 = vTemp;
992  assert( Vec_WrdSize(p1) >= Vec_WrdSize(p2) );
993  vTemp = Vec_WrdInvert( p2, -1 );
994  Vec_WrdFillExtra( vTemp, Vec_WrdFindMax(p1) + 1, ~((word)0) );
995  Vec_WrdForEachEntry( p1, Entry, i )
996  if ( Vec_WrdEntry(vTemp, Entry) != ~((word)0) )
997  Counter++;
998  Vec_WrdFree( vTemp );
999  return Counter;
1000 }
1001 
1002 /**Function*************************************************************
1003 
1004  Synopsis [Comparison procedure for two integers.]
1005 
1006  Description []
1007 
1008  SideEffects []
1009 
1010  SeeAlso []
1011 
1012 ***********************************************************************/
1013 static int Vec_WrdSortCompare1( word * pp1, word * pp2 )
1014 {
1015  // for some reason commenting out lines (as shown) led to crashing of the release version
1016  if ( *pp1 < *pp2 )
1017  return -1;
1018  if ( *pp1 > *pp2 ) //
1019  return 1;
1020  return 0; //
1021 }
1022 
1023 /**Function*************************************************************
1024 
1025  Synopsis [Comparison procedure for two integers.]
1026 
1027  Description []
1028 
1029  SideEffects []
1030 
1031  SeeAlso []
1032 
1033 ***********************************************************************/
1034 static int Vec_WrdSortCompare2( word * pp1, word * pp2 )
1035 {
1036  // for some reason commenting out lines (as shown) led to crashing of the release version
1037  if ( *pp1 > *pp2 )
1038  return -1;
1039  if ( *pp1 < *pp2 ) //
1040  return 1;
1041  return 0; //
1042 }
1043 
1044 /**Function*************************************************************
1045 
1046  Synopsis [Sorting the entries by their integer value.]
1047 
1048  Description []
1049 
1050  SideEffects []
1051 
1052  SeeAlso []
1053 
1054 ***********************************************************************/
1055 static inline void Vec_WrdSort( Vec_Wrd_t * p, int fReverse )
1056 {
1057  if ( fReverse )
1058  qsort( (void *)p->pArray, p->nSize, sizeof(word),
1059  (int (*)(const void *, const void *)) Vec_WrdSortCompare2 );
1060  else
1061  qsort( (void *)p->pArray, p->nSize, sizeof(word),
1062  (int (*)(const void *, const void *)) Vec_WrdSortCompare1 );
1063 }
1064 
1065 /**Function*************************************************************
1066 
1067  Synopsis [Leaves only unique entries.]
1068 
1069  Description []
1070 
1071  SideEffects []
1072 
1073  SeeAlso []
1074 
1075 ***********************************************************************/
1076 static inline void Vec_WrdUniqify( Vec_Wrd_t * p )
1077 {
1078  int i, k;
1079  if ( p->nSize < 2 )
1080  return;
1081  Vec_WrdSort( p, 0 );
1082  for ( i = k = 1; i < p->nSize; i++ )
1083  if ( p->pArray[i] != p->pArray[i-1] )
1084  p->pArray[k++] = p->pArray[i];
1085  p->nSize = k;
1086 }
1087 static inline int Vec_WrdUniqueCount( Vec_Wrd_t * vData, int nWordSize, Vec_Int_t ** pvMap )
1088 {
1089  int Result;
1090  Vec_Int_t * vDataInt = (Vec_Int_t *)vData;
1091  vDataInt->nSize *= 2;
1092  vDataInt->nCap *= 2;
1093  Result = Vec_IntUniqueCount( vDataInt, 2 * nWordSize, pvMap );
1094  vDataInt->nSize /= 2;
1095  vDataInt->nCap /= 2;
1096  return Result;
1097 }
1098 static inline Vec_Wrd_t * Vec_WrdUniqifyHash( Vec_Wrd_t * vData, int nWordSize )
1099 {
1100  Vec_Int_t * vResInt;
1101  Vec_Int_t * vDataInt = (Vec_Int_t *)vData;
1102  vDataInt->nSize *= 2;
1103  vDataInt->nCap *= 2;
1104  vResInt = Vec_IntUniqifyHash( vDataInt, 2 * nWordSize );
1105  vDataInt->nSize /= 2;
1106  vDataInt->nCap /= 2;
1107  vResInt->nSize /= 2;
1108  vResInt->nCap /= 2;
1109  return (Vec_Wrd_t *)vResInt;
1110 }
1111 
1112 /**Function*************************************************************
1113 
1114  Synopsis [Comparison procedure for two integers.]
1115 
1116  Description []
1117 
1118  SideEffects []
1119 
1120  SeeAlso []
1121 
1122 ***********************************************************************/
1123 static int Vec_WrdSortCompareUnsigned( word * pp1, word * pp2 )
1124 {
1125  if ( *pp1 < *pp2 )
1126  return -1;
1127  if ( *pp1 > *pp2 )
1128  return 1;
1129  return 0;
1130 }
1131 
1132 /**Function*************************************************************
1133 
1134  Synopsis [Sorting the entries by their integer value.]
1135 
1136  Description []
1137 
1138  SideEffects []
1139 
1140  SeeAlso []
1141 
1142 ***********************************************************************/
1143 static inline void Vec_WrdSortUnsigned( Vec_Wrd_t * p )
1144 {
1145  qsort( (void *)p->pArray, p->nSize, sizeof(word),
1146  (int (*)(const void *, const void *)) Vec_WrdSortCompareUnsigned );
1147 }
1148 
1149 
1150 /**Function*************************************************************
1151 
1152  Synopsis [Appends the contents of the second vector.]
1153 
1154  Description []
1155 
1156  SideEffects []
1157 
1158  SeeAlso []
1159 
1160 ***********************************************************************/
1161 static inline void Vec_WrdAppend( Vec_Wrd_t * vVec1, Vec_Wrd_t * vVec2 )
1162 {
1163  word Entry; int i;
1164  Vec_WrdForEachEntry( vVec2, Entry, i )
1165  Vec_WrdPush( vVec1, Entry );
1166 }
1167 
1168 
1170 
1171 #endif
1172 
1173 ////////////////////////////////////////////////////////////////////////
1174 /// END OF FILE ///
1175 ////////////////////////////////////////////////////////////////////////
1176 
char * memset()
static void Vec_WrdGrow(Vec_Wrd_t *p, int nCapMin)
Definition: vecWrd.h:469
static Vec_Wrd_t * Vec_WrdDupArray(Vec_Wrd_t *pVec)
Definition: vecWrd.h:230
static word Vec_WrdFindMax(Vec_Wrd_t *p)
Definition: vecWrd.h:849
static int Vec_WrdEqual(Vec_Wrd_t *p1, Vec_Wrd_t *p2)
Definition: vecWrd.h:963
static double Vec_WrdMemory(Vec_Wrd_t *p)
Definition: vecWrd.h:368
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static void Vec_WrdSortUnsigned(Vec_Wrd_t *p)
Definition: vecWrd.h:1143
static word * Vec_WrdGetEntryP(Vec_Wrd_t *p, int i)
Definition: vecWrd.h:551
static int Vec_WrdSortCompareUnsigned(word *pp1, word *pp2)
Definition: vecWrd.h:1123
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static int Vec_WrdCountCommon(Vec_Wrd_t *p1, Vec_Wrd_t *p2)
Definition: vecWrd.h:985
#define ABC_REALLOC(type, obj, num)
Definition: abc_global.h:233
static void Vec_WrdPush(Vec_Wrd_t *p, word Entry)
Definition: vecWrd.h:618
static word * Vec_WrdFetch(Vec_Wrd_t *p, int nWords)
Definition: vecWrd.h:740
static int Vec_WrdPushUnique(Vec_Wrd_t *p, word Entry)
Definition: vecWrd.h:719
static void Vec_WrdPushOrder(Vec_Wrd_t *p, word Entry)
Definition: vecWrd.h:668
static int Vec_WrdCap(Vec_Wrd_t *p)
Definition: vecWrd.h:352
word * pArray
Definition: vecWrd.h:47
static int Vec_WrdPushUniqueOrder(Vec_Wrd_t *p, word Entry)
Definition: vecWrd.h:698
char * memcpy()
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static word Vec_WrdEntryLast(Vec_Wrd_t *p)
Definition: vecWrd.h:452
static void Vec_WrdInsert(Vec_Wrd_t *p, int iHere, word Entry)
Definition: vecWrd.h:828
static void Vec_WrdReverseOrder(Vec_Wrd_t *p)
Definition: vecWrd.h:897
static int Vec_WrdSize(Vec_Wrd_t *p)
Definition: vecWrd.h:336
static void Vec_WrdFreeP(Vec_Wrd_t **p)
Definition: vecWrd.h:277
#define Vec_WrdForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecWrd.h:54
static void Vec_WrdPushFirst(Vec_Wrd_t *p, word Entry)
Definition: vecWrd.h:641
int nWords
Definition: abcNpn.c:127
int nSize
Definition: vecWrd.h:46
static int Vec_WrdSortCompare1(word *pp1, word *pp2)
Definition: vecWrd.h:1013
static word Vec_WrdSum(Vec_Wrd_t *p)
Definition: vecWrd.h:943
static void Vec_WrdUniqify(Vec_Wrd_t *p)
Definition: vecWrd.h:1076
static word Vec_WrdAddToEntry(Vec_Wrd_t *p, int i, word Addition)
Definition: vecWrd.h:435
static word Vec_WrdFindMin(Vec_Wrd_t *p)
Definition: vecWrd.h:873
static Vec_Wrd_t * Vec_WrdUniqifyHash(Vec_Wrd_t *vData, int nWordSize)
Definition: vecWrd.h:1098
static void Vec_WrdSetEntry(Vec_Wrd_t *p, int i, word Entry)
Definition: vecWrd.h:568
static void Vec_WrdClear(Vec_Wrd_t *p)
Definition: vecWrd.h:602
static void Vec_WrdShrink(Vec_Wrd_t *p, int nSizeNew)
Definition: vecWrd.h:585
static void Vec_WrdWriteEntry(Vec_Wrd_t *p, int i, word Entry)
Definition: vecWrd.h:418
static void Vec_WrdFill(Vec_Wrd_t *p, int nSize, word Fill)
Definition: vecWrd.h:489
static word * Vec_WrdLimit(Vec_Wrd_t *p)
Definition: vecWrd.h:320
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
static Vec_Wrd_t * Vec_WrdInvert(Vec_Wrd_t *p, word Fill)
Definition: vecWrd.h:920
static void Vec_WrdFree(Vec_Wrd_t *p)
Definition: vecWrd.h:260
int nCap
Definition: vecWrd.h:45
static Vec_Wrd_t * Vec_WrdStartFull(int nSize)
Definition: vecWrd.h:123
static Vec_Wrd_t * Vec_WrdStartNatural(int nSize)
Definition: vecWrd.h:143
static word Vec_WrdGetEntry(Vec_Wrd_t *p, int i)
Definition: vecWrd.h:534
static int Counter
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
Definition: abc_global.h:105
#define ABC_NAMESPACE_HEADER_END
Definition: abc_global.h:106
static Vec_Wrd_t * Vec_WrdAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecWrd.h:80
static int Vec_WrdFind(Vec_Wrd_t *p, word Entry)
Definition: vecWrd.h:782
static Vec_Wrd_t * Vec_WrdStart(int nSize)
Definition: vecWrd.h:103
static Vec_Int_t * Vec_IntUniqifyHash(Vec_Int_t *vData, int nIntSize)
Definition: vecInt.h:1464
static void Vec_WrdSort(Vec_Wrd_t *p, int fReverse)
Definition: vecWrd.h:1055
static word * Vec_WrdArray(Vec_Wrd_t *p)
Definition: vecWrd.h:316
static word * Vec_WrdReleaseArray(Vec_Wrd_t *p)
Definition: vecWrd.h:296
#define ABC_FREE(obj)
Definition: abc_global.h:232
static int Vec_WrdRemove(Vec_Wrd_t *p, word Entry)
Definition: vecWrd.h:802
static word Vec_WrdEntry(Vec_Wrd_t *p, int i)
Definition: vecWrd.h:384
static word Vec_WrdPop(Vec_Wrd_t *p)
Definition: vecWrd.h:765
static int Vec_WrdSortCompare2(word *pp1, word *pp2)
Definition: vecWrd.h:1034
#define assert(ex)
Definition: util_old.h:213
static Vec_Wrd_t * Vec_WrdAllocArrayCopy(word *pArray, int nSize)
Definition: vecWrd.h:186
static int Vec_IntUniqueCount(Vec_Int_t *vData, int nIntSize, Vec_Int_t **pvMap)
Definition: vecInt.h:1437
static void Vec_WrdAppend(Vec_Wrd_t *vVec1, Vec_Wrd_t *vVec2)
Definition: vecWrd.h:1161
static void Vec_WrdFillExtra(Vec_Wrd_t *p, int nSize, word Fill)
Definition: vecWrd.h:509
static Vec_Wrd_t * Vec_WrdDup(Vec_Wrd_t *pVec)
Definition: vecWrd.h:208
static int Vec_WrdUniqueCount(Vec_Wrd_t *vData, int nWordSize, Vec_Int_t **pvMap)
Definition: vecWrd.h:1087
typedefABC_NAMESPACE_HEADER_START struct Vec_Wrd_t_ Vec_Wrd_t
INCLUDES ///.
Definition: vecWrd.h:42
static Vec_Wrd_t * Vec_WrdAllocArray(word *pArray, int nSize)
Definition: vecWrd.h:165
static void Vec_WrdErase(Vec_Wrd_t *p)
Definition: vecWrd.h:254
static word * Vec_WrdEntryP(Vec_Wrd_t *p, int i)
Definition: vecWrd.h:401