BitVecPop
BitVecPop
Description
Pop the last bit from bitvector. Returns the value of the removed bit.
Parameters
| Name | Direction | Description |
|---|---|---|
bv |
in | Bitvector to pop bit from |
Usage example (from documentation)
bool last_bit = BitVecPop(&flags);Returns
Value of the popped bit (true/false)
Usage example (Cross-references)
Usage examples (Cross-references)
- In
BitVec.c:234:
}
bool BitVecPop(BitVec *bitvec) {
ValidateBitVec(bitvec);
if (bitvec->length == 0) { // Test BitVecPop function
bool test_bitvec_pop(void) {
WriteFmt("Testing BitVecPop\n");
BitVec bv = BitVecInit();
// Pop the last bit
bool popped = BitVecPop(&bv);
// Check result
// Pop another bit
popped = BitVecPop(&bv);
result = result && (popped == false) && (bv.length == 1);
result = result && (BitVecGet(&bv, 0) == true);
// Pop the last bit
popped = BitVecPop(&bv);
result = result && (popped == true) && (bv.length == 0); // Edge case tests
bool test_bitvec_pop_edge_cases(void) {
WriteFmt("Testing BitVecPop edge cases\n");
BitVec bv = BitVecInit(); // Test pop single element
BitVecPush(&bv, true);
bool popped = BitVecPop(&bv);
result = result && (popped == true) && (bv.length == 0); }
for (int i = 99; i >= 0; i--) {
popped = BitVecPop(&bv);
result = result && (popped == (i % 2 == 0));
result = result && (bv.length == (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