Skip to content
BitVecCapacity

BitVecCapacity

BitVecCapacity

Description

Get capacity of bitvector in bits.

Parameters

Name Direction Description
bv in Bitvector to get capacity of

Usage example (from documentation)

  u64 max_bits = BitVecCapacity(&flags);

Returns

Maximum number of bits bitvector can hold without reallocation

Usage example (Cross-references)

Usage examples (Cross-references)
    // Test BitVecLength and BitVecCapacity functions
    bool test_bitvec_length_capacity(void) {
        WriteFmt("Testing BitVecLength and BitVecCapacity\n");
    
        BitVec bv = BitVecInit();
    
        result = result && (BitVecLen(&bv) == 3);
        result = result && (BitVecCapacity(&bv) >= 3);
    
        // Reserve more space
        BitVecReserve(&bv, 100);
        result = result && (BitVecLen(&bv) == 3);
        result = result && (BitVecCapacity(&bv) >= 100);
    
        BitVecDeinit(&bv);
        // Test length and capacity macros if they exist
        result = result && (BitVecLen(&bv) == 2);
        result = result && (BitVecCapacity(&bv) >= 2);
    
        // Test some bit operations
    
        // Initially should be empty
        bool result = (BitVecLen(&bv) == 0) && (BitVecCapacity(&bv) == 0);
    
        // Add some bits
    
        result = result && (BitVecLen(&bv) == 3);
        result = result && (BitVecCapacity(&bv) >= 3);
    
        // Test empty check
        // Test all macros on empty bitvector
        result = result && (BitVecLen(&bv) == 0);
        result = result && (BitVecCapacity(&bv) == 0);
        result = result && BitVecEmpty(&bv);
        result = result && (BitVecByteSize(&bv) == 0);
    
        result = result && (BitVecLen(&bv) == 65);
        result = result && (BitVecCapacity(&bv) >= 65);
        result = result && !BitVecEmpty(&bv);
        result = result && (BitVecByteSize(&bv) >= 9); // At least 9 bytes for 65 bits
Last updated on