BitVecLen

Table of Contents

BitVecLen

Description

Get number of bits currently in bitvector.

Parameters

NameDirectionDescription
bvinBitvector to get length of

Usage example (from documentation)

  u64 num_bits = BitVecLen(&flags);

Usage example (Cross-references)

    
    // Check result should be: 101110
    result = result && (BitVecLen(&source) == 6);
    result = result && (BitVecGet(&source, 0) == true);
    result = result && (BitVecGet(&source, 1) == false);
    
    // Check final length
    result = result && (BitVecLen(&source) == 6); // 3 * 2 = 6
    
    BitVecDeinit(&source);
    
    // Check result should be: 101110
    result = result && (BitVecLen(&source) == 6);
    result = result && (BitVecGet(&source, 0) == true);
    result = result && (BitVecGet(&source, 1) == false);
    
    // Check final length
    result = result && (BitVecLen(&source) == 6); // 3 * 2 = 6
    
    BitVecDeinit(&source);
    
    // Initially empty
    bool result = (BitVecLen(&bv) == 0);
    
    // Push some bits
    BitVecPush(&bv, true);
    
    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);
    
    // Test length and capacity macros if they exist
    result = result && (BitVecLen(&bv) == 2);
    result = result && (BitVecCapacity(&bv) >= 2);
    
    // Initially should be empty
    bool result = (BitVecLen(&bv) == 0) && (BitVecCapacity(&bv) == 0);
    
    // Add some bits
    BitVecPush(&bv, true);
    
    result = result && (BitVecLen(&bv) == 3);
    result = result && (BitVecCapacity(&bv) >= 3);
    BitVecClear(&bv);
    result = result && BitVecEmpty(&bv);
    result = result && (BitVecLen(&bv) == 0);
    
    // Clean up
    if (cycle > 0) {
    result = result && (BitVecGet(&bv, 0) == true);
    result = result && (BitVecLen(&bv) == (size)(cycle + 1));
    }
    
    // Test all macros on empty bitvector
    result = result && (BitVecLen(&bv) == 0);
    result = result && (BitVecCapacity(&bv) == 0);
    result = result && BitVecEmpty(&bv);
    }
    
    result = result && (BitVecLen(&bv) == 65);
    result = result && (BitVecCapacity(&bv) >= 65);
    result = result && !BitVecEmpty(&bv);
    }
    
    result = result && (BitVecLen(&bv) == 64);
    result = result && (BitVecByteSize(&bv) >= 8); // At least 8 bytes for 64 bits
    /// TAGS: BitVec, Empty, Check
    ///
    #define BitVecEmpty(bv) (BitVecLen(bv) == 0)
    
    ///

Share :

Related Posts

VecInitAlignedWithDeepCopyStack

VecInitAlignedWithDeepCopyStack Description Initialize given vector with given alignment. It is mandatory to initialize vectors before use. Not doing so is undefined behaviour. Provided alignment is used to keep all objects at an aligned memory location, avoiding UB in some cases. It’s recommended to use aligned vector when dealing with structs containing unions. These vectors are best used where user doesn’t get a chance to or does not want to deinit vector, given that no data in vector needs to be deinitialized. Example includes, but does not limit to a Vec(i8), Vec(f32), etc…

Read More

VecInitStack

VecInitStack Description Initialize given vector using memory from stack. Such vectors cannot be dynamically resized. Doing so is UB. It is mandatory to initialize vectors before use. Not doing so is undefined behaviour. These vectors are best used where user doesn’t get a chance to or does not want to deinit vector, given that no data in vector needs to be deinitialized. Example includes, but does not limit to a Vec(i8), Vec(f32), etc… Stack inited vectors mustn’t be deinited after use.

Read More

ListInitT

ListInitT Description Initialize a list with default arguments.

Read More