21 #ifndef ABC__misc__vec__vecBit_h
22 #define ABC__misc__vec__vecBit_h
54 #define Vec_BitForEachEntry( vVec, Entry, i ) \
55 for ( i = 0; (i < Vec_BitSize(vVec)) && (((Entry) = Vec_BitEntry(vVec, i)), 1); i++ )
56 #define Vec_BitForEachEntryStart( vVec, Entry, i, Start ) \
57 for ( i = Start; (i < Vec_BitSize(vVec)) && (((Entry) = Vec_BitEntry(vVec, i)), 1); i++ )
58 #define Vec_BitForEachEntryStop( vVec, Entry, i, Stop ) \
59 for ( i = 0; (i < Stop) && (((Entry) = Vec_BitEntry(vVec, i)), 1); i++ )
60 #define Vec_BitForEachEntryStartStop( vVec, Entry, i, Start, Stop ) \
61 for ( i = Start; (i < Stop) && (((Entry) = Vec_BitEntry(vVec, i)), 1); i++ )
62 #define Vec_BitForEachEntryReverse( vVec, pEntry, i ) \
63 for ( i = Vec_BitSize(vVec) - 1; (i >= 0) && (((pEntry) = Vec_BitEntry(vVec, i)), 1); i-- )
83 nCap = (nCap >> 5) + ((nCap & 31) > 0);
87 p->pArray = nCap?
ABC_ALLOC(
int, nCap ) : NULL;
105 nSize = (nSize >> 5) + ((nSize & 31) > 0);
107 p->nSize = nSize * 32;
108 memset( p->pArray, 0,
sizeof(
int) * nSize );
126 nSize = (nSize >> 5) + ((nSize & 31) > 0);
128 p->nSize = nSize * 32;
129 memset( p->pArray, 0xff,
sizeof(
int) * nSize );
147 assert( (pVec->nSize & 31) == 0 );
149 p->nSize = pVec->nSize;
150 p->nCap = pVec->nSize;
151 p->pArray = p->nCap?
ABC_ALLOC(
int, p->nCap >> 5 ) : NULL;
152 memcpy( p->pArray, pVec->pArray,
sizeof(
int) * (p->nCap >> 5) );
205 int * pArray = p->pArray;
273 return !p ? 0.0 : 1.0 *
sizeof(int) * p->nCap +
sizeof(
Vec_Bit_t);
289 assert( i >= 0 && i < p->nSize );
290 return (p->pArray[i >> 5] >> (i & 31)) & 1;
306 assert( i >= 0 && i < p->nSize );
308 p->pArray[i >> 5] |= (1 << (i & 31));
309 else if ( Entry == 0 )
310 p->pArray[i >> 5] &= ~(1 << (i & 31));
344 if ( p->nCap >= nCapMin )
346 nCapMin = (nCapMin >> 5) + ((nCapMin & 31) > 0);
347 p->pArray =
ABC_REALLOC(
int, p->pArray, nCapMin );
349 p->nCap = nCapMin * 32;
367 nSize = (nSize >> 5) + ((nSize & 31) > 0);
370 for ( i = 0; i < nSize; i++ )
373 else if ( Fill == 1 )
375 for ( i = 0; i < nSize; i++ )
379 p->nSize = nSize * 32;
396 if ( nSize <= p->nSize )
398 if ( nSize > 2 * p->nCap )
400 else if ( nSize > p->nCap )
403 assert( p->nSize < nSize );
404 if ( (p->nSize >> 5) == (nSize >> 5) )
406 unsigned Mask = (~(~0 << (nSize-p->nSize)) << p->nSize);
408 p->pArray[nSize >> 5] |= Mask;
409 else if ( Fill == 0 )
410 p->pArray[nSize >> 5] &= ~Mask;
415 unsigned Mask1 = (p->nSize & 31) ? ~0 << (p->nSize & 31) : 0;
416 unsigned Mask2 = (nSize & 31) ? ~(~0 << (nSize & 31)) : 0;
417 int w1 = (p->nSize >> 5);
418 int w2 = (nSize >> 5);
421 p->pArray[w1] |= Mask1;
422 p->pArray[w2] |= Mask2;
423 for ( i = w1 + 1; i < w2; i++ )
426 else if ( Fill == 0 )
428 p->pArray[w1] &= ~Mask1;
429 p->pArray[w2] &= ~Mask2;
430 for ( i = w1 + 1; i < w2; i++ )
485 assert( p->nSize >= nSizeNew );
518 if ( p->nSize == p->nCap )
526 p->pArray[p->nSize >> 5] |= (1 << (p->nSize & 31));
527 else if ( Entry == 0 )
528 p->pArray[p->nSize >> 5] &= ~(1 << (p->nSize & 31));
566 uWord = (uWord & 0x55555555) + ((uWord>>1) & 0x55555555);
567 uWord = (uWord & 0x33333333) + ((uWord>>2) & 0x33333333);
568 uWord = (uWord & 0x0F0F0F0F) + ((uWord>>4) & 0x0F0F0F0F);
569 uWord = (uWord & 0x00FF00FF) + ((uWord>>8) & 0x00FF00FF);
570 return (uWord & 0x0000FFFF) + (uWord>>16);
586 unsigned * pArray = (
unsigned *)p->pArray;
587 int nWords = (p->nSize >> 5) + ((p->nSize & 31) > 0);
592 for ( i = 0; i <
nWords-1; i++ )
598 for ( i = 0; i <
nWords; i++ )
static void Vec_BitSetEntry(Vec_Bit_t *p, int i, int Entry)
static int Vec_BitGetEntry(Vec_Bit_t *p, int i)
static void Vec_BitShrink(Vec_Bit_t *p, int nSizeNew)
static int Vec_BitPop(Vec_Bit_t *p)
#define ABC_REALLOC(type, obj, num)
static Vec_Bit_t * Vec_BitDup(Vec_Bit_t *pVec)
#define ABC_ALLOC(type, num)
static void Vec_BitFill(Vec_Bit_t *p, int nSize, int Fill)
static Vec_Bit_t * Vec_BitStartFull(int nSize)
static void Vec_BitFreeP(Vec_Bit_t **p)
static void Vec_BitWriteEntry(Vec_Bit_t *p, int i, int Entry)
typedefABC_NAMESPACE_HEADER_START struct Vec_Bit_t_ Vec_Bit_t
INCLUDES ///.
static int * Vec_BitArray(Vec_Bit_t *p)
static int Vec_BitCountWord(unsigned uWord)
static Vec_Bit_t * Vec_BitStart(int nSize)
static int * Vec_BitReleaseArray(Vec_Bit_t *p)
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
static Vec_Bit_t * Vec_BitAlloc(int nCap)
FUNCTION DEFINITIONS ///.
#define ABC_NAMESPACE_HEADER_END
static int Vec_BitCap(Vec_Bit_t *p)
static int Vec_BitSize(Vec_Bit_t *p)
static void Vec_BitFillExtra(Vec_Bit_t *p, int nSize, int Fill)
static int Vec_BitEntryLast(Vec_Bit_t *p)
static int Vec_BitEntry(Vec_Bit_t *p, int i)
static void Vec_BitFree(Vec_Bit_t *p)
static void Vec_BitGrow(Vec_Bit_t *p, int nCapMin)
static int Vec_BitCount(Vec_Bit_t *p)
static void Vec_BitPush(Vec_Bit_t *p, int Entry)
static void Vec_BitClear(Vec_Bit_t *p)
static double Vec_BitMemory(Vec_Bit_t *p)