src/misc/vec/vecPtr.h File Reference

#include <stdio.h>
Include dependency graph for vecPtr.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Vec_Ptr_t_

Defines

#define Vec_PtrForEachEntry(vVec, pEntry, i)   for ( i = 0; (i < Vec_PtrSize(vVec)) && (((pEntry) = Vec_PtrEntry(vVec, i)), 1); i++ )
#define Vec_PtrForEachEntryStart(vVec, pEntry, i, Start)   for ( i = Start; (i < Vec_PtrSize(vVec)) && (((pEntry) = Vec_PtrEntry(vVec, i)), 1); i++ )
#define Vec_PtrForEachEntryStop(vVec, pEntry, i, Stop)   for ( i = 0; (i < Stop) && (((pEntry) = Vec_PtrEntry(vVec, i)), 1); i++ )
#define Vec_PtrForEachEntryStartStop(vVec, pEntry, i, Start, Stop)   for ( i = Start; (i < Stop) && (((pEntry) = Vec_PtrEntry(vVec, i)), 1); i++ )
#define Vec_PtrForEachEntryReverse(vVec, pEntry, i)   for ( i = Vec_PtrSize(vVec) - 1; (i >= 0) && (((pEntry) = Vec_PtrEntry(vVec, i)), 1); i-- )

Typedefs

typedef struct Vec_Ptr_t_ Vec_Ptr_t

Functions

static Vec_Ptr_tVec_PtrAlloc (int nCap)
static Vec_Ptr_tVec_PtrStart (int nSize)
static Vec_Ptr_tVec_PtrAllocArray (void **pArray, int nSize)
static Vec_Ptr_tVec_PtrAllocArrayCopy (void **pArray, int nSize)
static Vec_Ptr_tVec_PtrAllocSimInfo (int nEntries, int nWords)
static Vec_Ptr_tVec_PtrAllocTruthTables (int nVars)
static Vec_Ptr_tVec_PtrDup (Vec_Ptr_t *pVec)
static Vec_Ptr_tVec_PtrDupArray (Vec_Ptr_t *pVec)
static void Vec_PtrFree (Vec_Ptr_t *p)
static void ** Vec_PtrReleaseArray (Vec_Ptr_t *p)
static void ** Vec_PtrArray (Vec_Ptr_t *p)
static int Vec_PtrSize (Vec_Ptr_t *p)
static void * Vec_PtrEntry (Vec_Ptr_t *p, int i)
static void Vec_PtrDoubleSimInfo (Vec_Ptr_t *vInfo)
static void ** Vec_PtrEntryP (Vec_Ptr_t *p, int i)
static void Vec_PtrWriteEntry (Vec_Ptr_t *p, int i, void *Entry)
static void * Vec_PtrEntryLast (Vec_Ptr_t *p)
static void Vec_PtrGrow (Vec_Ptr_t *p, int nCapMin)
static void Vec_PtrFill (Vec_Ptr_t *p, int nSize, void *Entry)
static void Vec_PtrFillExtra (Vec_Ptr_t *p, int nSize, void *Entry)
static void * Vec_PtrGetEntry (Vec_Ptr_t *p, int i)
static void Vec_PtrSetEntry (Vec_Ptr_t *p, int i, void *Entry)
static void Vec_PtrShrink (Vec_Ptr_t *p, int nSizeNew)
static void Vec_PtrClear (Vec_Ptr_t *p)
static void Vec_PtrCopy (Vec_Ptr_t *pDest, Vec_Ptr_t *pSour)
static void Vec_PtrPush (Vec_Ptr_t *p, void *Entry)
static int Vec_PtrPushUnique (Vec_Ptr_t *p, void *Entry)
static void * Vec_PtrPop (Vec_Ptr_t *p)
static int Vec_PtrFind (Vec_Ptr_t *p, void *Entry)
static void Vec_PtrRemove (Vec_Ptr_t *p, void *Entry)
static void Vec_PtrReorder (Vec_Ptr_t *p, int nItems)
static void Vec_PtrSort (Vec_Ptr_t *p, int(*Vec_PtrSortCompare)())
static void Vec_PtrUniqify (Vec_Ptr_t *p, int(*Vec_PtrSortCompare)())

Define Documentation

#define Vec_PtrForEachEntry ( vVec,
pEntry,
 )     for ( i = 0; (i < Vec_PtrSize(vVec)) && (((pEntry) = Vec_PtrEntry(vVec, i)), 1); i++ )

MACRO DEFINITIONS ///

Definition at line 51 of file vecPtr.h.

#define Vec_PtrForEachEntryReverse ( vVec,
pEntry,
 )     for ( i = Vec_PtrSize(vVec) - 1; (i >= 0) && (((pEntry) = Vec_PtrEntry(vVec, i)), 1); i-- )

Definition at line 59 of file vecPtr.h.

#define Vec_PtrForEachEntryStart ( vVec,
pEntry,
i,
Start   )     for ( i = Start; (i < Vec_PtrSize(vVec)) && (((pEntry) = Vec_PtrEntry(vVec, i)), 1); i++ )

Definition at line 53 of file vecPtr.h.

#define Vec_PtrForEachEntryStartStop ( vVec,
pEntry,
i,
Start,
Stop   )     for ( i = Start; (i < Stop) && (((pEntry) = Vec_PtrEntry(vVec, i)), 1); i++ )

Definition at line 57 of file vecPtr.h.

#define Vec_PtrForEachEntryStop ( vVec,
pEntry,
i,
Stop   )     for ( i = 0; (i < Stop) && (((pEntry) = Vec_PtrEntry(vVec, i)), 1); i++ )

Definition at line 55 of file vecPtr.h.


Typedef Documentation

typedef struct Vec_Ptr_t_ Vec_Ptr_t

CFile****************************************************************

FileName [vecPtr.h]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Resizable arrays.]

Synopsis [Resizable arrays of generic pointers.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id
vecPtr.h,v 1.00 2005/06/20 00:00:00 alanmi Exp

] INCLUDES /// PARAMETERS /// BASIC TYPES ///

Definition at line 38 of file vecPtr.h.


Function Documentation

static Vec_Ptr_t* Vec_PtrAlloc ( int  nCap  )  [inline, static]

FUNCTION DEFINITIONS ///Function*************************************************************

Synopsis [Allocates a vector with the given capacity.]

Description []

SideEffects []

SeeAlso []

Definition at line 77 of file vecPtr.h.

00078 {
00079     Vec_Ptr_t * p;
00080     p = ALLOC( Vec_Ptr_t, 1 );
00081     if ( nCap > 0 && nCap < 8 )
00082         nCap = 8;
00083     p->nSize  = 0;
00084     p->nCap   = nCap;
00085     p->pArray = p->nCap? ALLOC( void *, p->nCap ) : NULL;
00086     return p;
00087 }

static Vec_Ptr_t* Vec_PtrAllocArray ( void **  pArray,
int  nSize 
) [inline, static]

Function*************************************************************

Synopsis [Creates the vector from an integer array of the given size.]

Description []

SideEffects []

SeeAlso []

Definition at line 120 of file vecPtr.h.

00121 {
00122     Vec_Ptr_t * p;
00123     p = ALLOC( Vec_Ptr_t, 1 );
00124     p->nSize  = nSize;
00125     p->nCap   = nSize;
00126     p->pArray = pArray;
00127     return p;
00128 }

static Vec_Ptr_t* Vec_PtrAllocArrayCopy ( void **  pArray,
int  nSize 
) [inline, static]

Function*************************************************************

Synopsis [Creates the vector from an integer array of the given size.]

Description []

SideEffects []

SeeAlso []

Definition at line 141 of file vecPtr.h.

00142 {
00143     Vec_Ptr_t * p;
00144     p = ALLOC( Vec_Ptr_t, 1 );
00145     p->nSize  = nSize;
00146     p->nCap   = nSize;
00147     p->pArray = ALLOC( void *, nSize );
00148     memcpy( p->pArray, pArray, sizeof(void *) * nSize );
00149     return p;
00150 }

static Vec_Ptr_t* Vec_PtrAllocSimInfo ( int  nEntries,
int  nWords 
) [inline, static]

Function*************************************************************

Synopsis [Allocates the array of simulation info.]

Description [Allocates the array containing given number of entries, each of which contains given number of unsigned words of simulation data. The resulting array can be freed using regular procedure Vec_PtrFree(). It is the responsibility of the user to ensure this array is never grown.]

SideEffects []

SeeAlso []

Definition at line 166 of file vecPtr.h.

00167 {
00168     void ** pMemory;
00169     unsigned * pInfo;
00170     int i;
00171     pMemory = (void **)ALLOC( char, (sizeof(void *) + sizeof(unsigned) * nWords) * nEntries );
00172     pInfo = (unsigned *)(pMemory + nEntries);
00173     for ( i = 0; i < nEntries; i++ )
00174         pMemory[i] = pInfo + i * nWords;
00175     return Vec_PtrAllocArray( pMemory, nEntries );
00176 }

static Vec_Ptr_t* Vec_PtrAllocTruthTables ( int  nVars  )  [inline, static]

Function*************************************************************

Synopsis [Allocates the array of truth tables for the given number of vars.]

Description []

SideEffects []

SeeAlso []

Definition at line 189 of file vecPtr.h.

00190 {
00191     Vec_Ptr_t * p;
00192     unsigned Masks[5] = { 0xAAAAAAAA, 0xCCCCCCCC, 0xF0F0F0F0, 0xFF00FF00, 0xFFFF0000 };
00193     unsigned * pTruth;
00194     int i, k, nWords;
00195     nWords = (nVars <= 5 ? 1 : (1 << (nVars - 5)));
00196     p = Vec_PtrAllocSimInfo( nVars, nWords );
00197     for ( i = 0; i < nVars; i++ )
00198     {
00199         pTruth = (unsigned *)p->pArray[i];
00200         if ( i < 5 )
00201         {
00202             for ( k = 0; k < nWords; k++ )
00203                 pTruth[k] = Masks[i];
00204         }
00205         else
00206         {
00207             for ( k = 0; k < nWords; k++ )
00208                 if ( k & (1 << (i-5)) )
00209                     pTruth[k] = ~(unsigned)0;
00210                 else
00211                     pTruth[k] = 0;
00212         }
00213     }
00214     return p;
00215 }

static void** Vec_PtrArray ( Vec_Ptr_t p  )  [inline, static]

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 311 of file vecPtr.h.

00312 {
00313     return p->pArray;
00314 }

static void Vec_PtrClear ( Vec_Ptr_t p  )  [inline, static]

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 558 of file vecPtr.h.

00559 {
00560     p->nSize = 0;
00561 }

static void Vec_PtrCopy ( Vec_Ptr_t pDest,
Vec_Ptr_t pSour 
) [inline, static]

Function*************************************************************

Synopsis [Copies the interger array.]

Description []

SideEffects []

SeeAlso []

Definition at line 574 of file vecPtr.h.

00575 {
00576     pDest->nSize = 0;
00577     Vec_PtrGrow( pDest, pSour->nSize );
00578     memcpy( pDest->pArray, pSour->pArray, sizeof(void *) * pSour->nSize );
00579     pDest->nSize = pSour->nSize;
00580 }

static void Vec_PtrDoubleSimInfo ( Vec_Ptr_t vInfo  )  [inline, static]

Function*************************************************************

Synopsis [Resizes the array of simulation info.]

Description []

SideEffects []

SeeAlso []

Definition at line 360 of file vecPtr.h.

00361 {
00362     Vec_Ptr_t * vInfoNew;
00363     int nWords;
00364     assert( Vec_PtrSize(vInfo) > 2 );
00365     // get the new array
00366     nWords = (unsigned *)Vec_PtrEntry(vInfo,1) - (unsigned *)Vec_PtrEntry(vInfo,0);
00367     vInfoNew = Vec_PtrAllocSimInfo( 2*Vec_PtrSize(vInfo), nWords );
00368     // copy the simulation info
00369     memcpy( Vec_PtrEntry(vInfoNew,0), Vec_PtrEntry(vInfo,0), Vec_PtrSize(vInfo) * nWords * 4 );
00370     // replace the array
00371     free( vInfo->pArray );
00372     vInfo->pArray = vInfoNew->pArray;
00373     vInfo->nSize *= 2;
00374     vInfo->nCap *= 2;
00375     // free the old array
00376     vInfoNew->pArray = NULL;
00377     free( vInfoNew );
00378 }

static Vec_Ptr_t* Vec_PtrDup ( Vec_Ptr_t pVec  )  [inline, static]

Function*************************************************************

Synopsis [Duplicates the integer array.]

Description []

SideEffects []

SeeAlso []

Definition at line 228 of file vecPtr.h.

00229 {
00230     Vec_Ptr_t * p;
00231     p = ALLOC( Vec_Ptr_t, 1 );
00232     p->nSize  = pVec->nSize;
00233     p->nCap   = pVec->nCap;
00234     p->pArray = p->nCap? ALLOC( void *, p->nCap ) : NULL;
00235     memcpy( p->pArray, pVec->pArray, sizeof(void *) * pVec->nSize );
00236     return p;
00237 }

static Vec_Ptr_t* Vec_PtrDupArray ( Vec_Ptr_t pVec  )  [inline, static]

Function*************************************************************

Synopsis [Transfers the array into another vector.]

Description []

SideEffects []

SeeAlso []

Definition at line 250 of file vecPtr.h.

00251 {
00252     Vec_Ptr_t * p;
00253     p = ALLOC( Vec_Ptr_t, 1 );
00254     p->nSize  = pVec->nSize;
00255     p->nCap   = pVec->nCap;
00256     p->pArray = pVec->pArray;
00257     pVec->nSize  = 0;
00258     pVec->nCap   = 0;
00259     pVec->pArray = NULL;
00260     return p;
00261 }

static void* Vec_PtrEntry ( Vec_Ptr_t p,
int  i 
) [inline, static]

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 343 of file vecPtr.h.

00344 {
00345     assert( i >= 0 && i < p->nSize );
00346     return p->pArray[i];
00347 }

static void* Vec_PtrEntryLast ( Vec_Ptr_t p  )  [inline, static]

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 425 of file vecPtr.h.

00426 {
00427     assert( p->nSize > 0 );
00428     return p->pArray[p->nSize-1];
00429 }

static void** Vec_PtrEntryP ( Vec_Ptr_t p,
int  i 
) [inline, static]

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 391 of file vecPtr.h.

00392 {
00393     assert( i >= 0 && i < p->nSize );
00394     return p->pArray + i;
00395 }

static void Vec_PtrFill ( Vec_Ptr_t p,
int  nSize,
void *  Entry 
) [inline, static]

Function*************************************************************

Synopsis [Fills the vector with given number of entries.]

Description []

SideEffects []

SeeAlso []

Definition at line 461 of file vecPtr.h.

00462 {
00463     int i;
00464     Vec_PtrGrow( p, nSize );
00465     for ( i = 0; i < nSize; i++ )
00466         p->pArray[i] = Entry;
00467     p->nSize = nSize;
00468 }

static void Vec_PtrFillExtra ( Vec_Ptr_t p,
int  nSize,
void *  Entry 
) [inline, static]

Function*************************************************************

Synopsis [Fills the vector with given number of entries.]

Description []

SideEffects []

SeeAlso []

Definition at line 481 of file vecPtr.h.

00482 {
00483     int i;
00484     if ( p->nSize >= nSize )
00485         return;
00486     assert( p->nSize < nSize );
00487     if ( 2 * p->nSize > nSize )
00488         Vec_PtrGrow( p, 2 * nSize );
00489     else
00490         Vec_PtrGrow( p, nSize );
00491     for ( i = p->nSize; i < nSize; i++ )
00492         p->pArray[i] = Entry;
00493     p->nSize = nSize;
00494 }

static int Vec_PtrFind ( Vec_Ptr_t p,
void *  Entry 
) [inline, static]

Function*************************************************************

Synopsis [Find entry.]

Description []

SideEffects []

SeeAlso []

Definition at line 654 of file vecPtr.h.

00655 {
00656     int i;
00657     for ( i = 0; i < p->nSize; i++ )
00658         if ( p->pArray[i] == Entry )
00659             return i;
00660     return -1;
00661 }

static void Vec_PtrFree ( Vec_Ptr_t p  )  [inline, static]

Function*************************************************************

Synopsis [Frees the vector.]

Description []

SideEffects []

SeeAlso []

Definition at line 274 of file vecPtr.h.

00275 {
00276     FREE( p->pArray );
00277     FREE( p );
00278 }

static void* Vec_PtrGetEntry ( Vec_Ptr_t p,
int  i 
) [inline, static]

Function*************************************************************

Synopsis [Returns the entry even if the place not exist.]

Description []

SideEffects []

SeeAlso []

Definition at line 507 of file vecPtr.h.

00508 {
00509     Vec_PtrFillExtra( p, i + 1, NULL );
00510     return Vec_PtrEntry( p, i );
00511 }

static void Vec_PtrGrow ( Vec_Ptr_t p,
int  nCapMin 
) [inline, static]

Function*************************************************************

Synopsis [Resizes the vector to the given capacity.]

Description []

SideEffects []

SeeAlso []

Definition at line 442 of file vecPtr.h.

00443 {
00444     if ( p->nCap >= nCapMin )
00445         return;
00446     p->pArray = REALLOC( void *, p->pArray, nCapMin ); 
00447     p->nCap   = nCapMin;
00448 }

static void* Vec_PtrPop ( Vec_Ptr_t p  )  [inline, static]

Function*************************************************************

Synopsis [Returns the last entry and removes it from the list.]

Description []

SideEffects []

SeeAlso []

Definition at line 637 of file vecPtr.h.

00638 {
00639     assert( p->nSize > 0 );
00640     return p->pArray[--p->nSize];
00641 }

static void Vec_PtrPush ( Vec_Ptr_t p,
void *  Entry 
) [inline, static]

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 593 of file vecPtr.h.

00594 {
00595     if ( p->nSize == p->nCap )
00596     {
00597         if ( p->nCap < 16 )
00598             Vec_PtrGrow( p, 16 );
00599         else
00600             Vec_PtrGrow( p, 2 * p->nCap );
00601     }
00602     p->pArray[p->nSize++] = Entry;
00603 }

static int Vec_PtrPushUnique ( Vec_Ptr_t p,
void *  Entry 
) [inline, static]

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 616 of file vecPtr.h.

00617 {
00618     int i;
00619     for ( i = 0; i < p->nSize; i++ )
00620         if ( p->pArray[i] == Entry )
00621             return 1;
00622     Vec_PtrPush( p, Entry );
00623     return 0;
00624 }

static void** Vec_PtrReleaseArray ( Vec_Ptr_t p  )  [inline, static]

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 291 of file vecPtr.h.

00292 {
00293     void ** pArray = p->pArray;
00294     p->nCap = 0;
00295     p->nSize = 0;
00296     p->pArray = NULL;
00297     return pArray;
00298 }

static void Vec_PtrRemove ( Vec_Ptr_t p,
void *  Entry 
) [inline, static]

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 674 of file vecPtr.h.

00675 {
00676     int i;
00677     // delete assuming that it is closer to the end
00678     for ( i = p->nSize - 1; i >= 0; i-- )
00679         if ( p->pArray[i] == Entry )
00680             break;
00681     assert( i >= 0 );
00682 /*
00683     // delete assuming that it is closer to the beginning
00684     for ( i = 0; i < p->nSize; i++ )
00685         if ( p->pArray[i] == Entry )
00686             break;
00687     assert( i < p->nSize );
00688 */
00689     for ( i++; i < p->nSize; i++ )
00690         p->pArray[i-1] = p->pArray[i];
00691     p->nSize--;
00692 }

static void Vec_PtrReorder ( Vec_Ptr_t p,
int  nItems 
) [inline, static]

Function*************************************************************

Synopsis [Moves the first nItems to the end.]

Description []

SideEffects []

SeeAlso []

Definition at line 705 of file vecPtr.h.

00706 {
00707     assert( nItems < p->nSize );
00708     Vec_PtrGrow( p, nItems + p->nSize );
00709     memmove( (char **)p->pArray + p->nSize, p->pArray, nItems * sizeof(void*) );
00710     memmove( p->pArray, (char **)p->pArray + nItems, p->nSize * sizeof(void*) );
00711 }

static void Vec_PtrSetEntry ( Vec_Ptr_t p,
int  i,
void *  Entry 
) [inline, static]

Function*************************************************************

Synopsis [Inserts the entry even if the place does not exist.]

Description []

SideEffects []

SeeAlso []

Definition at line 524 of file vecPtr.h.

00525 {
00526     Vec_PtrFillExtra( p, i + 1, NULL );
00527     Vec_PtrWriteEntry( p, i, Entry );
00528 }

static void Vec_PtrShrink ( Vec_Ptr_t p,
int  nSizeNew 
) [inline, static]

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 541 of file vecPtr.h.

00542 {
00543     assert( p->nSize >= nSizeNew );
00544     p->nSize = nSizeNew;
00545 }

static int Vec_PtrSize ( Vec_Ptr_t p  )  [inline, static]

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 327 of file vecPtr.h.

00328 {
00329     return p->nSize;
00330 }

static void Vec_PtrSort ( Vec_Ptr_t p,
int(*)()  Vec_PtrSortCompare 
) [inline, static]

Function*************************************************************

Synopsis [Sorting the entries by their integer value.]

Description []

SideEffects []

SeeAlso []

Definition at line 724 of file vecPtr.h.

00725 {
00726     if ( p->nSize < 2 )
00727         return;
00728     qsort( (void *)p->pArray, p->nSize, sizeof(void *), 
00729             (int (*)(const void *, const void *)) Vec_PtrSortCompare );
00730 }

static Vec_Ptr_t* Vec_PtrStart ( int  nSize  )  [inline, static]

Function*************************************************************

Synopsis [Allocates a vector with the given size and cleans it.]

Description []

SideEffects []

SeeAlso []

Definition at line 100 of file vecPtr.h.

00101 {
00102     Vec_Ptr_t * p;
00103     p = Vec_PtrAlloc( nSize );
00104     p->nSize = nSize;
00105     memset( p->pArray, 0, sizeof(void *) * nSize );
00106     return p;
00107 }

static void Vec_PtrUniqify ( Vec_Ptr_t p,
int(*)()  Vec_PtrSortCompare 
) [inline, static]

Function*************************************************************

Synopsis [Sorting the entries by their integer value.]

Description []

SideEffects []

SeeAlso []

Definition at line 743 of file vecPtr.h.

00744 {
00745     int i, k;
00746     if ( p->nSize < 2 )
00747         return;
00748     qsort( (void *)p->pArray, p->nSize, sizeof(void *), 
00749             (int (*)(const void *, const void *)) Vec_PtrSortCompare );
00750     for ( i = k = 1; i < p->nSize; i++ )
00751         if ( p->pArray[i] != p->pArray[i-1] )
00752             p->pArray[k++] = p->pArray[i];
00753     p->nSize = k;
00754 }

static void Vec_PtrWriteEntry ( Vec_Ptr_t p,
int  i,
void *  Entry 
) [inline, static]

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 408 of file vecPtr.h.

00409 {
00410     assert( i >= 0 && i < p->nSize );
00411     p->pArray[i] = Entry;
00412 }


Generated on Tue Jan 5 12:19:22 2010 for abc70930 by  doxygen 1.6.1