abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
vecPtr.h
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [vecPtr.h]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Resizable arrays.]
8 
9  Synopsis [Resizable arrays of generic pointers.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: vecPtr.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #ifndef ABC__misc__vec__vecPtr_h
22 #define ABC__misc__vec__vecPtr_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_Ptr_t_ Vec_Ptr_t;
43 struct Vec_Ptr_t_
44 {
45  int nCap;
46  int nSize;
47  void ** pArray;
48 };
49 
50 ////////////////////////////////////////////////////////////////////////
51 /// MACRO DEFINITIONS ///
52 ////////////////////////////////////////////////////////////////////////
53 
54 // iterators through entries
55 #define Vec_PtrForEachEntry( Type, vVec, pEntry, i ) \
56  for ( i = 0; (i < Vec_PtrSize(vVec)) && (((pEntry) = (Type)Vec_PtrEntry(vVec, i)), 1); i++ )
57 #define Vec_PtrForEachEntryStart( Type, vVec, pEntry, i, Start ) \
58  for ( i = Start; (i < Vec_PtrSize(vVec)) && (((pEntry) = (Type)Vec_PtrEntry(vVec, i)), 1); i++ )
59 #define Vec_PtrForEachEntryStop( Type, vVec, pEntry, i, Stop ) \
60  for ( i = 0; (i < Stop) && (((pEntry) = (Type)Vec_PtrEntry(vVec, i)), 1); i++ )
61 #define Vec_PtrForEachEntryStartStop( Type, vVec, pEntry, i, Start, Stop ) \
62  for ( i = Start; (i < Stop) && (((pEntry) = (Type)Vec_PtrEntry(vVec, i)), 1); i++ )
63 #define Vec_PtrForEachEntryReverse( Type, vVec, pEntry, i ) \
64  for ( i = Vec_PtrSize(vVec) - 1; (i >= 0) && (((pEntry) = (Type)Vec_PtrEntry(vVec, i)), 1); i-- )
65 #define Vec_PtrForEachEntryTwo( Type1, vVec1, Type2, vVec2, pEntry1, pEntry2, i ) \
66  for ( i = 0; (i < Vec_PtrSize(vVec1)) && (((pEntry1) = (Type1)Vec_PtrEntry(vVec1, i)), 1) && (((pEntry2) = (Type2)Vec_PtrEntry(vVec2, i)), 1); i++ )
67 
68 ////////////////////////////////////////////////////////////////////////
69 /// FUNCTION DEFINITIONS ///
70 ////////////////////////////////////////////////////////////////////////
71 
72 /**Function*************************************************************
73 
74  Synopsis [Allocates a vector with the given capacity.]
75 
76  Description []
77 
78  SideEffects []
79 
80  SeeAlso []
81 
82 ***********************************************************************/
83 static inline Vec_Ptr_t * Vec_PtrAlloc( int nCap )
84 {
85  Vec_Ptr_t * p;
86  p = ABC_ALLOC( Vec_Ptr_t, 1 );
87  if ( nCap > 0 && nCap < 8 )
88  nCap = 8;
89  p->nSize = 0;
90  p->nCap = nCap;
91  p->pArray = p->nCap? ABC_ALLOC( void *, p->nCap ) : NULL;
92  return p;
93 }
94 
95 /**Function*************************************************************
96 
97  Synopsis [Allocates a vector with the given size and cleans it.]
98 
99  Description []
100 
101  SideEffects []
102 
103  SeeAlso []
104 
105 ***********************************************************************/
106 static inline Vec_Ptr_t * Vec_PtrStart( int nSize )
107 {
108  Vec_Ptr_t * p;
109  p = Vec_PtrAlloc( nSize );
110  p->nSize = nSize;
111  memset( p->pArray, 0, sizeof(void *) * nSize );
112  return p;
113 }
114 
115 /**Function*************************************************************
116 
117  Synopsis [Creates the vector from an integer array of the given size.]
118 
119  Description []
120 
121  SideEffects []
122 
123  SeeAlso []
124 
125 ***********************************************************************/
126 static inline Vec_Ptr_t * Vec_PtrAllocArray( void ** pArray, int nSize )
127 {
128  Vec_Ptr_t * p;
129  p = ABC_ALLOC( Vec_Ptr_t, 1 );
130  p->nSize = nSize;
131  p->nCap = nSize;
132  p->pArray = pArray;
133  return p;
134 }
135 
136 /**Function*************************************************************
137 
138  Synopsis [Creates the vector from an integer array of the given size.]
139 
140  Description []
141 
142  SideEffects []
143 
144  SeeAlso []
145 
146 ***********************************************************************/
147 static inline Vec_Ptr_t * Vec_PtrAllocArrayCopy( void ** pArray, int nSize )
148 {
149  Vec_Ptr_t * p;
150  p = ABC_ALLOC( Vec_Ptr_t, 1 );
151  p->nSize = nSize;
152  p->nCap = nSize;
153  p->pArray = ABC_ALLOC( void *, nSize );
154  memcpy( p->pArray, pArray, sizeof(void *) * nSize );
155  return p;
156 }
157 
158 /**Function*************************************************************
159 
160  Synopsis [Duplicates the integer array.]
161 
162  Description []
163 
164  SideEffects []
165 
166  SeeAlso []
167 
168 ***********************************************************************/
169 static inline Vec_Ptr_t * Vec_PtrDup( Vec_Ptr_t * pVec )
170 {
171  Vec_Ptr_t * p;
172  p = ABC_ALLOC( Vec_Ptr_t, 1 );
173  p->nSize = pVec->nSize;
174  p->nCap = pVec->nCap;
175  p->pArray = p->nCap? ABC_ALLOC( void *, p->nCap ) : NULL;
176  memcpy( p->pArray, pVec->pArray, sizeof(void *) * pVec->nSize );
177  return p;
178 }
179 static inline Vec_Ptr_t * Vec_PtrDupStr( Vec_Ptr_t * pVec )
180 {
181  int i;
182  Vec_Ptr_t * p = Vec_PtrDup( pVec );
183  for ( i = 0; i < p->nSize; i++ )
184  p->pArray[i] = Abc_UtilStrsav( (char *)p->pArray[i] );
185  return p;
186 }
187 
188 /**Function*************************************************************
189 
190  Synopsis [Transfers the array into another vector.]
191 
192  Description []
193 
194  SideEffects []
195 
196  SeeAlso []
197 
198 ***********************************************************************/
199 static inline Vec_Ptr_t * Vec_PtrDupArray( Vec_Ptr_t * pVec )
200 {
201  Vec_Ptr_t * p;
202  p = ABC_ALLOC( Vec_Ptr_t, 1 );
203  p->nSize = pVec->nSize;
204  p->nCap = pVec->nCap;
205  p->pArray = pVec->pArray;
206  pVec->nSize = 0;
207  pVec->nCap = 0;
208  pVec->pArray = NULL;
209  return p;
210 }
211 
212 /**Function*************************************************************
213 
214  Synopsis [Frees the vector.]
215 
216  Description []
217 
218  SideEffects []
219 
220  SeeAlso []
221 
222 ***********************************************************************/
223 static inline void Vec_PtrFree( Vec_Ptr_t * p )
224 {
225  ABC_FREE( p->pArray );
226  ABC_FREE( p );
227 }
228 
229 /**Function*************************************************************
230 
231  Synopsis []
232 
233  Description []
234 
235  SideEffects []
236 
237  SeeAlso []
238 
239 ***********************************************************************/
240 static inline void Vec_PtrFreeP( Vec_Ptr_t ** p )
241 {
242  if ( *p == NULL )
243  return;
244  ABC_FREE( (*p)->pArray );
245  ABC_FREE( (*p) );
246 }
247 
248 /**Function*************************************************************
249 
250  Synopsis []
251 
252  Description []
253 
254  SideEffects []
255 
256  SeeAlso []
257 
258 ***********************************************************************/
259 static inline void ** Vec_PtrReleaseArray( Vec_Ptr_t * p )
260 {
261  void ** pArray = p->pArray;
262  p->nCap = 0;
263  p->nSize = 0;
264  p->pArray = NULL;
265  return pArray;
266 }
267 
268 /**Function*************************************************************
269 
270  Synopsis []
271 
272  Description []
273 
274  SideEffects []
275 
276  SeeAlso []
277 
278 ***********************************************************************/
279 static inline void ** Vec_PtrArray( Vec_Ptr_t * p )
280 {
281  return p->pArray;
282 }
283 
284 /**Function*************************************************************
285 
286  Synopsis []
287 
288  Description []
289 
290  SideEffects []
291 
292  SeeAlso []
293 
294 ***********************************************************************/
295 static inline int Vec_PtrSize( Vec_Ptr_t * p )
296 {
297  return p->nSize;
298 }
299 
300 /**Function*************************************************************
301 
302  Synopsis []
303 
304  Description []
305 
306  SideEffects []
307 
308  SeeAlso []
309 
310 ***********************************************************************/
311 static inline int Vec_PtrCap( Vec_Ptr_t * p )
312 {
313  return p->nCap;
314 }
315 
316 /**Function*************************************************************
317 
318  Synopsis []
319 
320  Description []
321 
322  SideEffects []
323 
324  SeeAlso []
325 
326 ***********************************************************************/
327 static inline double Vec_PtrMemory( Vec_Ptr_t * p )
328 {
329  return !p ? 0.0 : 1.0 * sizeof(void *) * p->nCap + sizeof(Vec_Ptr_t);
330 }
331 
332 /**Function*************************************************************
333 
334  Synopsis []
335 
336  Description []
337 
338  SideEffects []
339 
340  SeeAlso []
341 
342 ***********************************************************************/
343 static inline int Vec_PtrCountZero( Vec_Ptr_t * p )
344 {
345  int i, Counter = 0;
346  for ( i = 0; i < p->nSize; i++ )
347  Counter += (p->pArray[i] == NULL);
348  return Counter;
349 }
350 
351 /**Function*************************************************************
352 
353  Synopsis []
354 
355  Description []
356 
357  SideEffects []
358 
359  SeeAlso []
360 
361 ***********************************************************************/
362 static inline void * Vec_PtrEntry( Vec_Ptr_t * p, int i )
363 {
364  assert( i >= 0 && i < p->nSize );
365  return p->pArray[i];
366 }
367 
368 /**Function*************************************************************
369 
370  Synopsis []
371 
372  Description []
373 
374  SideEffects []
375 
376  SeeAlso []
377 
378 ***********************************************************************/
379 static inline void ** Vec_PtrEntryP( Vec_Ptr_t * p, int i )
380 {
381  assert( i >= 0 && i < p->nSize );
382  return p->pArray + i;
383 }
384 
385 /**Function*************************************************************
386 
387  Synopsis []
388 
389  Description []
390 
391  SideEffects []
392 
393  SeeAlso []
394 
395 ***********************************************************************/
396 static inline void Vec_PtrWriteEntry( Vec_Ptr_t * p, int i, void * Entry )
397 {
398  assert( i >= 0 && i < p->nSize );
399  p->pArray[i] = Entry;
400 }
401 
402 /**Function*************************************************************
403 
404  Synopsis []
405 
406  Description []
407 
408  SideEffects []
409 
410  SeeAlso []
411 
412 ***********************************************************************/
413 static inline void * Vec_PtrEntryLast( Vec_Ptr_t * p )
414 {
415  assert( p->nSize > 0 );
416  return p->pArray[p->nSize-1];
417 }
418 
419 /**Function*************************************************************
420 
421  Synopsis [Resizes the vector to the given capacity.]
422 
423  Description []
424 
425  SideEffects []
426 
427  SeeAlso []
428 
429 ***********************************************************************/
430 static inline void Vec_PtrGrow( Vec_Ptr_t * p, int nCapMin )
431 {
432  if ( p->nCap >= nCapMin )
433  return;
434  p->pArray = ABC_REALLOC( void *, p->pArray, nCapMin );
435  p->nCap = nCapMin;
436 }
437 
438 /**Function*************************************************************
439 
440  Synopsis [Fills the vector with given number of entries.]
441 
442  Description []
443 
444  SideEffects []
445 
446  SeeAlso []
447 
448 ***********************************************************************/
449 static inline void Vec_PtrFill( Vec_Ptr_t * p, int nSize, void * Entry )
450 {
451  int i;
452  Vec_PtrGrow( p, nSize );
453  for ( i = 0; i < nSize; i++ )
454  p->pArray[i] = Entry;
455  p->nSize = nSize;
456 }
457 
458 /**Function*************************************************************
459 
460  Synopsis [Fills the vector with given number of entries.]
461 
462  Description []
463 
464  SideEffects []
465 
466  SeeAlso []
467 
468 ***********************************************************************/
469 static inline void Vec_PtrFillExtra( Vec_Ptr_t * p, int nSize, void * Fill )
470 {
471  int i;
472  if ( nSize <= p->nSize )
473  return;
474  if ( nSize > 2 * p->nCap )
475  Vec_PtrGrow( p, nSize );
476  else if ( nSize > p->nCap )
477  Vec_PtrGrow( p, 2 * p->nCap );
478  for ( i = p->nSize; i < nSize; i++ )
479  p->pArray[i] = Fill;
480  p->nSize = nSize;
481 }
482 
483 /**Function*************************************************************
484 
485  Synopsis [Returns the entry even if the place not exist.]
486 
487  Description []
488 
489  SideEffects []
490 
491  SeeAlso []
492 
493 ***********************************************************************/
494 static inline void * Vec_PtrGetEntry( Vec_Ptr_t * p, int i )
495 {
496  Vec_PtrFillExtra( p, i + 1, NULL );
497  return Vec_PtrEntry( p, i );
498 }
499 
500 /**Function*************************************************************
501 
502  Synopsis [Inserts the entry even if the place does not exist.]
503 
504  Description []
505 
506  SideEffects []
507 
508  SeeAlso []
509 
510 ***********************************************************************/
511 static inline void Vec_PtrSetEntry( Vec_Ptr_t * p, int i, void * Entry )
512 {
513  Vec_PtrFillExtra( p, i + 1, NULL );
514  Vec_PtrWriteEntry( p, i, Entry );
515 }
516 
517 /**Function*************************************************************
518 
519  Synopsis []
520 
521  Description []
522 
523  SideEffects []
524 
525  SeeAlso []
526 
527 ***********************************************************************/
528 static inline void Vec_PtrShrink( Vec_Ptr_t * p, int nSizeNew )
529 {
530  assert( p->nSize >= nSizeNew );
531  p->nSize = nSizeNew;
532 }
533 
534 /**Function*************************************************************
535 
536  Synopsis []
537 
538  Description []
539 
540  SideEffects []
541 
542  SeeAlso []
543 
544 ***********************************************************************/
545 static inline void Vec_PtrClear( Vec_Ptr_t * p )
546 {
547  p->nSize = 0;
548 }
549 
550 /**Function*************************************************************
551 
552  Synopsis [Deallocates array of memory pointers.]
553 
554  Description []
555 
556  SideEffects []
557 
558  SeeAlso []
559 
560 ***********************************************************************/
561 static inline void Vec_PtrFreeData( Vec_Ptr_t * p )
562 {
563  void * pTemp; int i;
564  if ( p == NULL ) return;
565  Vec_PtrForEachEntry( void *, p, pTemp, i )
566  if ( pTemp != (void *)(ABC_PTRINT_T)1 && pTemp != (void *)(ABC_PTRINT_T)2 )
567  ABC_FREE( pTemp );
568 }
569 static inline void Vec_PtrFreeFree( Vec_Ptr_t * p )
570 {
571  if ( p == NULL ) return;
572  Vec_PtrFreeData( p );
573  Vec_PtrFree( p );
574 }
575 
576 /**Function*************************************************************
577 
578  Synopsis [Copies the interger array.]
579 
580  Description []
581 
582  SideEffects []
583 
584  SeeAlso []
585 
586 ***********************************************************************/
587 static inline void Vec_PtrCopy( Vec_Ptr_t * pDest, Vec_Ptr_t * pSour )
588 {
589  pDest->nSize = 0;
590  Vec_PtrGrow( pDest, pSour->nSize );
591  memcpy( pDest->pArray, pSour->pArray, sizeof(void *) * pSour->nSize );
592  pDest->nSize = pSour->nSize;
593 }
594 
595 /**Function*************************************************************
596 
597  Synopsis []
598 
599  Description []
600 
601  SideEffects []
602 
603  SeeAlso []
604 
605 ***********************************************************************/
606 static inline void Vec_PtrPush( Vec_Ptr_t * p, void * Entry )
607 {
608  if ( p->nSize == p->nCap )
609  {
610  if ( p->nCap < 16 )
611  Vec_PtrGrow( p, 16 );
612  else
613  Vec_PtrGrow( p, 2 * p->nCap );
614  }
615  p->pArray[p->nSize++] = Entry;
616 }
617 
618 /**Function*************************************************************
619 
620  Synopsis []
621 
622  Description []
623 
624  SideEffects []
625 
626  SeeAlso []
627 
628 ***********************************************************************/
629 static inline void Vec_PtrPushFirst( Vec_Ptr_t * p, void * Entry )
630 {
631  int i;
632  if ( p->nSize == p->nCap )
633  {
634  if ( p->nCap < 16 )
635  Vec_PtrGrow( p, 16 );
636  else
637  Vec_PtrGrow( p, 2 * p->nCap );
638  }
639  p->nSize++;
640  for ( i = p->nSize - 1; i >= 1; i-- )
641  p->pArray[i] = p->pArray[i-1];
642  p->pArray[0] = Entry;
643 }
644 
645 /**Function*************************************************************
646 
647  Synopsis []
648 
649  Description []
650 
651  SideEffects []
652 
653  SeeAlso []
654 
655 ***********************************************************************/
656 static inline int Vec_PtrPushUnique( Vec_Ptr_t * p, void * Entry )
657 {
658  int i;
659  for ( i = 0; i < p->nSize; i++ )
660  if ( p->pArray[i] == Entry )
661  return 1;
662  Vec_PtrPush( p, Entry );
663  return 0;
664 }
665 
666 /**Function*************************************************************
667 
668  Synopsis [Returns the last entry and removes it from the list.]
669 
670  Description []
671 
672  SideEffects []
673 
674  SeeAlso []
675 
676 ***********************************************************************/
677 static inline void * Vec_PtrPop( Vec_Ptr_t * p )
678 {
679  assert( p->nSize > 0 );
680  return p->pArray[--p->nSize];
681 }
682 
683 /**Function*************************************************************
684 
685  Synopsis [Find entry.]
686 
687  Description []
688 
689  SideEffects []
690 
691  SeeAlso []
692 
693 ***********************************************************************/
694 static inline int Vec_PtrFind( Vec_Ptr_t * p, void * Entry )
695 {
696  int i;
697  for ( i = 0; i < p->nSize; i++ )
698  if ( p->pArray[i] == Entry )
699  return i;
700  return -1;
701 }
702 
703 /**Function*************************************************************
704 
705  Synopsis []
706 
707  Description []
708 
709  SideEffects []
710 
711  SeeAlso []
712 
713 ***********************************************************************/
714 static inline void Vec_PtrRemove( Vec_Ptr_t * p, void * Entry )
715 {
716  int i;
717  // delete assuming that it is closer to the end
718  for ( i = p->nSize - 1; i >= 0; i-- )
719  if ( p->pArray[i] == Entry )
720  break;
721  assert( i >= 0 );
722 /*
723  // delete assuming that it is closer to the beginning
724  for ( i = 0; i < p->nSize; i++ )
725  if ( p->pArray[i] == Entry )
726  break;
727  assert( i < p->nSize );
728 */
729  for ( i++; i < p->nSize; i++ )
730  p->pArray[i-1] = p->pArray[i];
731  p->nSize--;
732 }
733 
734 /**Function*************************************************************
735 
736  Synopsis [Interts entry at the index iHere. Shifts other entries.]
737 
738  Description []
739 
740  SideEffects []
741 
742  SeeAlso []
743 
744 ***********************************************************************/
745 static inline void Vec_PtrInsert( Vec_Ptr_t * p, int iHere, void * Entry )
746 {
747  int i;
748  assert( iHere >= 0 && iHere < p->nSize );
749  Vec_PtrPush( p, 0 );
750  for ( i = p->nSize - 1; i > iHere; i-- )
751  p->pArray[i] = p->pArray[i-1];
752  p->pArray[i] = Entry;
753 }
754 
755 /**Function*************************************************************
756 
757  Synopsis [Moves the first nItems to the end.]
758 
759  Description []
760 
761  SideEffects []
762 
763  SeeAlso []
764 
765 ***********************************************************************/
766 static inline void Vec_PtrReorder( Vec_Ptr_t * p, int nItems )
767 {
768  assert( nItems < p->nSize );
769  Vec_PtrGrow( p, nItems + p->nSize );
770  memmove( (char **)p->pArray + p->nSize, p->pArray, nItems * sizeof(void*) );
771  memmove( p->pArray, (char **)p->pArray + nItems, p->nSize * sizeof(void*) );
772 }
773 
774 /**Function*************************************************************
775 
776  Synopsis [Reverses the order of entries.]
777 
778  Description []
779 
780  SideEffects []
781 
782  SeeAlso []
783 
784 ***********************************************************************/
785 static inline void Vec_PtrReverseOrder( Vec_Ptr_t * p )
786 {
787  void * Temp;
788  int i;
789  for ( i = 0; i < p->nSize/2; i++ )
790  {
791  Temp = p->pArray[i];
792  p->pArray[i] = p->pArray[p->nSize-1-i];
793  p->pArray[p->nSize-1-i] = Temp;
794  }
795 }
796 
797 /**Function*************************************************************
798 
799  Synopsis [Checks if two vectors are equal.]
800 
801  Description []
802 
803  SideEffects []
804 
805  SeeAlso []
806 
807 ***********************************************************************/
808 static inline int Vec_PtrEqual( Vec_Ptr_t * p1, Vec_Ptr_t * p2 )
809 {
810  int i;
811  if ( p1->nSize != p2->nSize )
812  return 0;
813  for ( i = 0; i < p1->nSize; i++ )
814  if ( p1->pArray[i] != p2->pArray[i] )
815  return 0;
816  return 1;
817 }
818 
819 /**Function*************************************************************
820 
821  Synopsis [Comparison procedure for two integers.]
822 
823  Description []
824 
825  SideEffects []
826 
827  SeeAlso []
828 
829 ***********************************************************************/
830 static int Vec_PtrSortComparePtr( void ** pp1, void ** pp2 )
831 {
832  if ( *pp1 < *pp2 )
833  return -1;
834  if ( *pp1 > *pp2 )
835  return 1;
836  return 0;
837 }
838 
839 /**Function*************************************************************
840 
841  Synopsis [Sorting the entries by their integer value.]
842 
843  Description []
844 
845  SideEffects []
846 
847  SeeAlso []
848 
849 ***********************************************************************/
850 static void Vec_PtrSort( Vec_Ptr_t * p, int (*Vec_PtrSortCompare)() ) ___unused;
851 static void Vec_PtrSort( Vec_Ptr_t * p, int (*Vec_PtrSortCompare)() )
852 {
853  if ( p->nSize < 2 )
854  return;
855  if ( Vec_PtrSortCompare == NULL )
856  qsort( (void *)p->pArray, p->nSize, sizeof(void *),
857  (int (*)(const void *, const void *)) Vec_PtrSortComparePtr );
858  else
859  qsort( (void *)p->pArray, p->nSize, sizeof(void *),
860  (int (*)(const void *, const void *)) Vec_PtrSortCompare );
861 }
862 
863 /**Function*************************************************************
864 
865  Synopsis [Sorting the entries by their integer value.]
866 
867  Description []
868 
869  SideEffects []
870 
871  SeeAlso []
872 
873 ***********************************************************************/
874 static void Vec_PtrUniqify( Vec_Ptr_t * p, int (*Vec_PtrSortCompare)() ) ___unused;
875 static void Vec_PtrUniqify( Vec_Ptr_t * p, int (*Vec_PtrSortCompare)() )
876 {
877  int i, k;
878  if ( p->nSize < 2 )
879  return;
880  Vec_PtrSort( p, Vec_PtrSortCompare );
881  for ( i = k = 1; i < p->nSize; i++ )
882  if ( p->pArray[i] != p->pArray[i-1] )
883  p->pArray[k++] = p->pArray[i];
884  p->nSize = k;
885 }
886 static void Vec_PtrUniqify2( Vec_Ptr_t * p, int (*Vec_PtrSortCompare)(void**, void**), void (*Vec_PtrObjFree)(void*), Vec_Int_t * vCounts ) ___unused;
887 static void Vec_PtrUniqify2( Vec_Ptr_t * p, int (*Vec_PtrSortCompare)(void**, void**), void (*Vec_PtrObjFree)(void*), Vec_Int_t * vCounts )
888 {
889  int i, k;
890  if ( vCounts )
891  Vec_IntFill( vCounts, 1, 1 );
892  if ( p->nSize < 2 )
893  return;
894  Vec_PtrSort( p, (int (*)())Vec_PtrSortCompare );
895  for ( i = k = 1; i < p->nSize; i++ )
896  if ( Vec_PtrSortCompare(p->pArray+i, p->pArray+k-1) != 0 )
897  {
898  p->pArray[k++] = p->pArray[i];
899  if ( vCounts )
900  Vec_IntPush( vCounts, 1 );
901  }
902  else
903  {
904  if ( Vec_PtrObjFree )
905  Vec_PtrObjFree( p->pArray[i] );
906  if ( vCounts )
907  Vec_IntAddToEntry( vCounts, Vec_IntSize(vCounts)-1, 1 );
908  }
909  p->nSize = k;
910  assert( vCounts == NULL || Vec_IntSize(vCounts) == Vec_PtrSize(p) );
911 }
912 
913 
914 
915 /**Function*************************************************************
916 
917  Synopsis [Allocates the array of simulation info.]
918 
919  Description [Allocates the array containing given number of entries,
920  each of which contains given number of unsigned words of simulation data.
921  The resulting array can be freed using regular procedure Vec_PtrFree().
922  It is the responsibility of the user to ensure this array is never grown.]
923 
924  SideEffects []
925 
926  SeeAlso []
927 
928 ***********************************************************************/
929 static inline Vec_Ptr_t * Vec_PtrAllocSimInfo( int nEntries, int nWords )
930 {
931  void ** pMemory;
932  unsigned * pInfo;
933  int i;
934  pMemory = (void **)ABC_ALLOC( char, (sizeof(void *) + sizeof(unsigned) * nWords) * nEntries );
935  pInfo = (unsigned *)(pMemory + nEntries);
936  for ( i = 0; i < nEntries; i++ )
937  pMemory[i] = pInfo + i * nWords;
938  return Vec_PtrAllocArray( pMemory, nEntries );
939 }
940 
941 /**Function*************************************************************
942 
943  Synopsis [Cleans simulation info of each entry beginning with iWord.]
944 
945  Description []
946 
947  SideEffects []
948 
949  SeeAlso []
950 
951 ***********************************************************************/
952 static inline int Vec_PtrReadWordsSimInfo( Vec_Ptr_t * p )
953 {
954  return (unsigned *)Vec_PtrEntry(p,1) - (unsigned *)Vec_PtrEntry(p,0);
955 }
956 
957 /**Function*************************************************************
958 
959  Synopsis [Cleans simulation info of each entry beginning with iWord.]
960 
961  Description []
962 
963  SideEffects []
964 
965  SeeAlso []
966 
967 ***********************************************************************/
968 static inline void Vec_PtrCleanSimInfo( Vec_Ptr_t * vInfo, int iWord, int nWords )
969 {
970  int i;
971  for ( i = 0; i < vInfo->nSize; i++ )
972  memset( (char*)Vec_PtrEntry(vInfo,i) + 4*iWord, 0, 4*(nWords-iWord) );
973 }
974 
975 /**Function*************************************************************
976 
977  Synopsis [Cleans simulation info of each entry beginning with iWord.]
978 
979  Description []
980 
981  SideEffects []
982 
983  SeeAlso []
984 
985 ***********************************************************************/
986 static inline void Vec_PtrFillSimInfo( Vec_Ptr_t * vInfo, int iWord, int nWords )
987 {
988  int i;
989  for ( i = 0; i < vInfo->nSize; i++ )
990  memset( (char*)Vec_PtrEntry(vInfo,i) + 4*iWord, 0xFF, 4*(nWords-iWord) );
991 }
992 
993 /**Function*************************************************************
994 
995  Synopsis [Resizes the array of simulation info.]
996 
997  Description [Doubles the number of objects for which siminfo is allocated.]
998 
999  SideEffects []
1000 
1001  SeeAlso []
1002 
1003 ***********************************************************************/
1004 static inline void Vec_PtrDoubleSimInfo( Vec_Ptr_t * vInfo )
1005 {
1006  Vec_Ptr_t * vInfoNew;
1007  int nWords;
1008  assert( Vec_PtrSize(vInfo) > 1 );
1009  // get the new array
1010  nWords = (unsigned *)Vec_PtrEntry(vInfo,1) - (unsigned *)Vec_PtrEntry(vInfo,0);
1011  vInfoNew = Vec_PtrAllocSimInfo( 2*Vec_PtrSize(vInfo), nWords );
1012  // copy the simulation info
1013  memcpy( Vec_PtrEntry(vInfoNew,0), Vec_PtrEntry(vInfo,0), Vec_PtrSize(vInfo) * nWords * 4 );
1014  // replace the array
1015  ABC_FREE( vInfo->pArray );
1016  vInfo->pArray = vInfoNew->pArray;
1017  vInfo->nSize *= 2;
1018  vInfo->nCap *= 2;
1019  // free the old array
1020  vInfoNew->pArray = NULL;
1021  ABC_FREE( vInfoNew );
1022 }
1023 
1024 /**Function*************************************************************
1025 
1026  Synopsis [Resizes the array of simulation info.]
1027 
1028  Description [Doubles the number of simulation patterns stored for each object.]
1029 
1030  SideEffects []
1031 
1032  SeeAlso []
1033 
1034 ***********************************************************************/
1035 static inline void Vec_PtrReallocSimInfo( Vec_Ptr_t * vInfo )
1036 {
1037  Vec_Ptr_t * vInfoNew;
1038  int nWords, i;
1039  assert( Vec_PtrSize(vInfo) > 1 );
1040  // get the new array
1041  nWords = (unsigned *)Vec_PtrEntry(vInfo,1) - (unsigned *)Vec_PtrEntry(vInfo,0);
1042  vInfoNew = Vec_PtrAllocSimInfo( Vec_PtrSize(vInfo), 2*nWords );
1043  // copy the simulation info
1044  for ( i = 0; i < vInfo->nSize; i++ )
1045  memcpy( Vec_PtrEntry(vInfoNew,i), Vec_PtrEntry(vInfo,i), nWords * 4 );
1046  // replace the array
1047  ABC_FREE( vInfo->pArray );
1048  vInfo->pArray = vInfoNew->pArray;
1049  // free the old array
1050  vInfoNew->pArray = NULL;
1051  ABC_FREE( vInfoNew );
1052 }
1053 
1054 /**Function*************************************************************
1055 
1056  Synopsis [Allocates the array of truth tables for the given number of vars.]
1057 
1058  Description []
1059 
1060  SideEffects []
1061 
1062  SeeAlso []
1063 
1064 ***********************************************************************/
1065 static inline Vec_Ptr_t * Vec_PtrAllocTruthTables( int nVars )
1066 {
1067  Vec_Ptr_t * p;
1068  unsigned Masks[5] = { 0xAAAAAAAA, 0xCCCCCCCC, 0xF0F0F0F0, 0xFF00FF00, 0xFFFF0000 };
1069  unsigned * pTruth;
1070  int i, k, nWords;
1071  nWords = (nVars <= 5 ? 1 : (1 << (nVars - 5)));
1072  p = Vec_PtrAllocSimInfo( nVars, nWords );
1073  for ( i = 0; i < nVars; i++ )
1074  {
1075  pTruth = (unsigned *)p->pArray[i];
1076  if ( i < 5 )
1077  {
1078  for ( k = 0; k < nWords; k++ )
1079  pTruth[k] = Masks[i];
1080  }
1081  else
1082  {
1083  for ( k = 0; k < nWords; k++ )
1084  if ( k & (1 << (i-5)) )
1085  pTruth[k] = ~(unsigned)0;
1086  else
1087  pTruth[k] = 0;
1088  }
1089  }
1090  return p;
1091 }
1092 
1093 
1094 
1096 
1097 #endif
1098 
1099 
1100 ////////////////////////////////////////////////////////////////////////
1101 /// END OF FILE ///
1102 ////////////////////////////////////////////////////////////////////////
1103 
char * memset()
static void Vec_PtrReverseOrder(Vec_Ptr_t *p)
Definition: vecPtr.h:785
static Vec_Ptr_t * Vec_PtrStart(int nSize)
Definition: vecPtr.h:106
static int Vec_PtrSortComparePtr(void **pp1, void **pp2)
Definition: vecPtr.h:830
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static void ** Vec_PtrEntryP(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:379
static void Vec_PtrSetEntry(Vec_Ptr_t *p, int i, void *Entry)
Definition: vecPtr.h:511
#define ___unused
Definition: abc_global.h:68
static void Vec_PtrCopy(Vec_Ptr_t *pDest, Vec_Ptr_t *pSour)
Definition: vecPtr.h:587
static int Vec_PtrSortCompare(void **pp1, void **pp2)
Definition: abcLutmin.c:351
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static void Vec_PtrFill(Vec_Ptr_t *p, int nSize, void *Entry)
Definition: vecPtr.h:449
static int Vec_PtrPushUnique(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:656
static void Vec_PtrInsert(Vec_Ptr_t *p, int iHere, void *Entry)
Definition: vecPtr.h:745
#define ABC_REALLOC(type, obj, num)
Definition: abc_global.h:233
static void Vec_PtrGrow(Vec_Ptr_t *p, int nCapMin)
Definition: vecPtr.h:430
static void Vec_PtrDoubleSimInfo(Vec_Ptr_t *vInfo)
Definition: vecPtr.h:1004
static Vec_Ptr_t * Vec_PtrAllocArrayCopy(void **pArray, int nSize)
Definition: vecPtr.h:147
static void Vec_PtrFreeFree(Vec_Ptr_t *p)
Definition: vecPtr.h:569
static void Vec_PtrFillExtra(Vec_Ptr_t *p, int nSize, void *Fill)
Definition: vecPtr.h:469
static void Vec_PtrCleanSimInfo(Vec_Ptr_t *vInfo, int iWord, int nWords)
Definition: vecPtr.h:968
static void Vec_PtrSort(Vec_Ptr_t *p, int(*Vec_PtrSortCompare)()) ___unused
Definition: vecPtr.h:851
static void * Vec_PtrGetEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:494
char * memcpy()
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static Vec_Ptr_t * Vec_PtrDup(Vec_Ptr_t *pVec)
Definition: vecPtr.h:169
static void Vec_PtrFillSimInfo(Vec_Ptr_t *vInfo, int iWord, int nWords)
Definition: vecPtr.h:986
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
static void * Vec_PtrPop(Vec_Ptr_t *p)
Definition: vecPtr.h:677
int nSize
Definition: vecPtr.h:46
int nWords
Definition: abcNpn.c:127
static int Vec_PtrFind(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:694
static void Vec_PtrRemove(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:714
char * memmove()
static void Vec_PtrUniqify(Vec_Ptr_t *p, int(*Vec_PtrSortCompare)()) ___unused
Definition: vecPtr.h:875
static Vec_Ptr_t * Vec_PtrAllocTruthTables(int nVars)
Definition: vecPtr.h:1065
static void Vec_PtrPushFirst(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:629
static void * Vec_PtrEntryLast(Vec_Ptr_t *p)
Definition: vecPtr.h:413
static void Vec_IntAddToEntry(Vec_Int_t *p, int i, int Addition)
Definition: bblif.c:302
int nCap
Definition: vecPtr.h:45
void ** pArray
Definition: vecPtr.h:47
static void Vec_IntFill(Vec_Int_t *p, int nSize, int Fill)
Definition: bblif.c:356
if(last==0)
Definition: sparse_int.h:34
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
static int Counter
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
Definition: abc_global.h:105
static double Vec_PtrMemory(Vec_Ptr_t *p)
Definition: vecPtr.h:327
#define ABC_NAMESPACE_HEADER_END
Definition: abc_global.h:106
static int Vec_PtrCountZero(Vec_Ptr_t *p)
Definition: vecPtr.h:343
static int Vec_PtrCap(Vec_Ptr_t *p)
Definition: vecPtr.h:311
static void Vec_PtrWriteEntry(Vec_Ptr_t *p, int i, void *Entry)
Definition: vecPtr.h:396
static Vec_Ptr_t * Vec_PtrDupArray(Vec_Ptr_t *pVec)
Definition: vecPtr.h:199
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
static int Vec_PtrReadWordsSimInfo(Vec_Ptr_t *p)
Definition: vecPtr.h:952
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
#define ABC_FREE(obj)
Definition: abc_global.h:232
static Vec_Ptr_t * Vec_PtrAllocArray(void **pArray, int nSize)
Definition: vecPtr.h:126
static void Vec_PtrFreeP(Vec_Ptr_t **p)
Definition: vecPtr.h:240
static void Vec_PtrReallocSimInfo(Vec_Ptr_t *vInfo)
Definition: vecPtr.h:1035
#define assert(ex)
Definition: util_old.h:213
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
static int Vec_PtrEqual(Vec_Ptr_t *p1, Vec_Ptr_t *p2)
Definition: vecPtr.h:808
static void Vec_PtrReorder(Vec_Ptr_t *p, int nItems)
Definition: vecPtr.h:766
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
static void Vec_PtrShrink(Vec_Ptr_t *p, int nSizeNew)
Definition: vecPtr.h:528
char * Abc_UtilStrsav(char *s)
Definition: starter.c:47
static Vec_Ptr_t * Vec_PtrDupStr(Vec_Ptr_t *pVec)
Definition: vecPtr.h:179
static void ** Vec_PtrArray(Vec_Ptr_t *p)
Definition: vecPtr.h:279
static void Vec_PtrFreeData(Vec_Ptr_t *p)
Definition: vecPtr.h:561
static Vec_Ptr_t * Vec_PtrAllocSimInfo(int nEntries, int nWords)
Definition: vecPtr.h:929
static void Vec_PtrUniqify2(Vec_Ptr_t *p, int(*Vec_PtrSortCompare)(void **, void **), void(*Vec_PtrObjFree)(void *), Vec_Int_t *vCounts) ___unused
Definition: vecPtr.h:887
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
static void ** Vec_PtrReleaseArray(Vec_Ptr_t *p)
Definition: vecPtr.h:259