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) {
    printf("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) {
    printf("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

BitVecRemoveLast

BitVecRemoveLast Description Remove the last occurrence of a specific bit value. Returns true if a bit was found and removed, false otherwise.

Read More

BitVecRemoveFirst

BitVecRemoveFirst Description Remove the first occurrence of a specific bit value. Returns true if a bit was found and removed, false otherwise.

Read More

BitVecRemoveAll

BitVecRemoveAll Description Remove all occurrences of a specific bit value. Returns the number of bits that were removed.

Read More