BitVecPop
Description
Pop the last bit from bitvector.
Parameters
| Name | Direction | Description |
|---|---|---|
bv |
in,out | Bitvector to pop bit from. |
Usage example (from documentation)
bool last_bit = BitVecPop(&flags);Success
Returns the value of the removed bit (true/false). Bitvector length shrinks by one; capacity is unchanged.
Failure
Function cannot fail. Calling on an empty bitvector is a caller bug and aborts via LOG_FATAL.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
BitVec.c:309:
}
bool BitVecPop(BitVec *bitvec) {
ValidateBitVec(bitvec);
if (bitvec->length == 0) { DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecPop\n");
BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
// Pop the last bit
bool popped = BitVecPop(&bv);
// Check result
// Pop another bit
popped = BitVecPop(&bv);
result = result && (popped == false) && (BitVecLen(&bv) == 1);
result = result && (BitVecGet(&bv, 0) == true);
// Pop the last bit
popped = BitVecPop(&bv);
result = result && (popped == true) && (BitVecLen(&bv) == 0); DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecPop edge cases\n");
BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc)); // Test pop single element
BitVecPush(&bv, true);
bool popped = BitVecPop(&bv);
result = result && (popped == true) && (BitVecLen(&bv) == 0); }
for (int i = 99; i >= 0; i--) {
popped = BitVecPop(&bv);
result = result && (popped == (i % 2 == 0));
result = result && (BitVecLen(&bv) == (size)i);
// Test NULL bitvec pointer - should abort
BitVecPop(NULL);
return false;
// Test pop from empty bitvec - should abort
BitVecPop(&bv);
BitVecDeinit(&bv);
Last updated on