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

BitVecCorrelation

BitVecCorrelation Description Calculate Pearson correlation coefficient between two bitvectors. Treats bits as 0/1 values and computes linear correlation.

Read More

BitVecEntropy

BitVecEntropy Description Calculate information entropy of a bitvector. Entropy measures the randomness/information content of the bit pattern.

Read More

BitVecRemoveRange

BitVecRemoveRange Description Remove multiple consecutive bits starting at a specific position. All bits after the removed range are shifted left.

Read More