BitVecPop

Table of Contents

BitVecPop

Description

Pop the last bit from bitvector. Returns the value of the removed bit.

Parameters

NameDirectionDescription
bvinBitvector to pop bit from

Usage example (from documentation)

  bool last_bit = BitVecPop(&flags);

Usage example (Cross-references)

    }
    
    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);

Share :

Related Posts

BitVecShiftRight

BitVecShiftRight Description Shift all bits in bitvector to the right by specified positions. New bits on the left are filled with zeros.

Read More

BitVecShiftLeft

BitVecShiftLeft Description Shift all bits in bitvector to the left by specified positions. New bits on the right are filled with zeros.

Read More

BitVecNot

BitVecNot Description Perform bitwise NOT operation on a bitvector. Result is stored in the first bitvector.

Read More