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

BitVecSignedCompare

BitVecSignedCompare Description Compare two bitvectors as signed integers (MSB is sign bit).

Read More

BitVecCompare

BitVecCompare Description Compare two bitvectors lexicographically. Comparison is done bit by bit from left to right.

Read More

BitVecWeightCompare

BitVecWeightCompare Description Compare two bitvectors by their Hamming weights (number of 1s).

Read More