BitVecShrinkToFit

Table of Contents

BitVecShrinkToFit

Description

Reduce bitvector capacity to match its current length. Frees any unused memory allocated beyond the current length.

Parameters

NameDirectionDescription
bvinBitvector to shrink

Usage example (from documentation)

  BitVecShrinkToFit(&flags);  // Free unused capacity

Usage example (Cross-references)

    }
    
    void BitVecShrinkToFit(BitVec *bv) {
    ValidateBitVec(bv);
    if (bv->length == 0) {
    // Test BitVecShrinkToFit function
    bool test_bitvec_shrink_to_fit(void) {
    WriteFmt("Testing BitVecShrinkToFit\n");
    
    BitVec bv = BitVecInit();
    
    // Shrink to fit
    BitVecShrinkToFit(&bv);
    
    // Check that capacity is now closer to length
    // Edge case tests
    bool test_bitvec_shrink_to_fit_edge_cases(void) {
    WriteFmt("Testing BitVecShrinkToFit edge cases\n");
    
    BitVec bv     = BitVecInit();
    
    // Test shrink on empty bitvec
    BitVecShrinkToFit(&bv);
    result = result && (bv.length == 0) && (bv.capacity >= 0);
    // Test shrink on single element
    BitVecPush(&bv, true);
    BitVecShrinkToFit(&bv);
    result = result && (bv.length == 1) && (bv.capacity >= 1);
    result = result && (BitVecGet(&bv, 0) == true);
    
    // Test multiple shrinks (should be safe)
    BitVecShrinkToFit(&bv);
    BitVecShrinkToFit(&bv);
    result = result && (bv.length == 1);
    // Test multiple shrinks (should be safe)
    BitVecShrinkToFit(&bv);
    BitVecShrinkToFit(&bv);
    result = result && (bv.length == 1);
    BitVecReserve(&bv, 1000);
    BitVecClear(&bv);
    BitVecShrinkToFit(&bv);
    result = result && (bv.length == 0);
    // Reu64 operations
    BitVecReserve(&bv1, cycle * 20);
    BitVecShrinkToFit(&bv2);
    
    // Verify data integrity
    
    // Test NULL bitvec pointer - should abort
    BitVecShrinkToFit(NULL);
    
    return false;

Share :

Related Posts

BitVecReserve

BitVecReserve Description Reserve space for at least n bits in bitvector. Does not change the length, only ensures capacity.

Read More

BitVecMatches

BitVecMatches Description Match bitvector against pattern with wildcards. Wildcards allow flexible pattern matching where some positions can be “any bit”.

Read More

BitVecDeinit

BitVecDeinit Description Deinitialize bitvector and free all allocated memory. After calling this, the bitvector should not be used unless re-initialized.

Read More