Skip to content

BitVecData

Description

Pointer to the raw u64-packed storage backing the bitvector. The caller MUST NOT free this pointer or write past BitVecByteSize(bv) bytes. Useful for serialising the underlying bits or for hand-rolled bit-level routines outside the standard BitVecGet/Set/Flip access pattern.

Parameters

Name Direction Description
bv in Bitvector to query.

Returns

Pointer to the backing u64 array, or NULL when the bitvector has never been allocated into.

Usage example (Cross-references)

Usage examples (Cross-references)
        // Check initial state
        bool result =
            (BitVecLen(&bitvec) == 0 && BitVecCapacity(&bitvec) == 0 && BitVecData(&bitvec) == NULL &&
             bitvec.byte_size == 0);
        bool result = (BitVecLen(&bv) == 0);
        result      = result && (BitVecCapacity(&bv) == 0);
        result      = result && (BitVecData(&bv) == NULL);
        result      = result && (bv.byte_size == 0);
    
        // Check that data was allocated
        bool result = (BitVecLen(&bv) == 3) && (BitVecData(&bv) != NULL);
    
        // Deinitialize
        result = result && (BitVecLen(&bv) == 0);
        result = result && (BitVecCapacity(&bv) == 0);
        result = result && (BitVecData(&bv) == NULL);
        result = result && (bv.byte_size == 0);
        bool result = (BitVecCapacity(&bv) >= 50);
        result      = result && (BitVecLen(&bv) == 0);     // Length should still be 0
        result      = result && (BitVecData(&bv) != NULL); // Memory should be allocated
    
        // Add some bits to make sure the reserved space works
    
        // Check initial state
        bool result            = (BitVecLen(&bv) == 4) && (BitVecData(&bv) != NULL);
        u64  original_capacity = BitVecCapacity(&bv);
        result = result && (BitVecLen(&bv) == 0);
        result = result && (BitVecCapacity(&bv) == original_capacity);
        result = result && (BitVecData(&bv) != NULL); // Memory should still be allocated
    
        // Test that we can still add data after clearing
    
        bool result = (BitVecLen(&bv1) == 0) && (BitVecLen(&bv2) == 0) && (BitVecLen(&bv3) == 0);
        result      = result && (BitVecData(&bv1) == NULL) && (BitVecData(&bv2) == NULL) && (BitVecData(&bv3) == NULL);
    
        // Clean up all
        // Test reserving 0 (should be safe no-op)
        BitVecReserve(&bv, 0);
        result = result && (BitVecCapacity(&bv) == 0) && (BitVecData(&bv) == NULL);
    
        // Test reserving 1 bit (minimum meaningful size)
        // Test reserving 1 bit (minimum meaningful size)
        BitVecReserve(&bv, 1);
        result = result && (BitVecCapacity(&bv) >= 1) && (BitVecData(&bv) != NULL);
    
        // Test very large but reasonable reservation
        u64       bits      = IntBitLength(value);
        u64       bytes     = bits == 0 ? 0 : CEIL_DIV(bits, 8u);
        const u8 *magnitude = (const u8 *)BitVecData(INT_BITS(value));
        for (u64 i = 0; i < bytes; i++) {
            hash ^= (u64)magnitude[i];
        u64       bits      = IntBitLength(&value->significand);
        u64       bytes     = bits == 0 ? 0 : CEIL_DIV(bits, 8u);
        const u8 *magnitude = (const u8 *)BitVecData(&value->significand.bits);
        for (u64 i = 0; i < bytes; i++) {
            hash ^= (u64)magnitude[i];
Last updated on