BitVecForeachIdx

Table of Contents

BitVecForeachIdx

Description

Iterate over each bit var of given bitvector bv at each index idx into the bitvector. The variables var and idx declared and defined by this macro. idx will start from 0 and will go till bv->length - 1

Parameters

NameDirectionDescription
bvin,outBitvector to iterate over.
varinName of variable to be used which’ll contain bit value at iterated index idx
idxinName of variable to be used for iterating over indices.

Usage example (Cross-references)

    // Test BitVecForeachIdx macro
    bool test_bitvec_foreach_idx(void) {
    WriteFmt("Testing BitVecForeachIdx macro\n");
    
    BitVec bv = BitVecInit();
    bool pattern_correct = true;
    
    BitVecForeachIdx(&bv, bit, idx) {
    if (idx == 0 || idx == 2) {
    pattern_correct = pattern_correct && (bit == true);
    
    // Test foreach idx on empty bitvec
    BitVecForeachIdx(&bv, bit, idx) {
    (void)bit;
    result = false; // Should not execute
    // Test foreach idx on single element
    BitVecPush(&bv, false);
    BitVecForeachIdx(&bv, bit, idx) {
    result   = result && (idx == 0);
    result   = result && (bit == false);
    
    u64 expected_idx = 0;
    BitVecForeachIdx(&bv, bit, idx) {
    (void)bit;
    result = result && (idx == expected_idx);
    count1++;
    }
    BitVecForeachIdx(&bv, bitval, i) {
    (void)bitval;
    count2++;
    // Test BitVecForeachIdx macro
    bool test_bitvec_foreach_idx(void) {
    WriteFmt("Testing BitVecForeachIdx macro\n");
    
    BitVec bv = BitVecInit();
    bool pattern_correct = true;
    
    BitVecForeachIdx(&bv, bit, idx) {
    if (idx == 0 || idx == 2) {
    pattern_correct = pattern_correct && (bit == true);
    
    // Test foreach idx on empty bitvec
    BitVecForeachIdx(&bv, bit, idx) {
    (void)bit;
    result = false; // Should not execute
    // Test foreach idx on single element
    BitVecPush(&bv, false);
    BitVecForeachIdx(&bv, bit, idx) {
    result   = result && (idx == 0);
    result   = result && (bit == false);
    
    u64 expected_idx = 0;
    BitVecForeachIdx(&bv, bit, idx) {
    (void)bit;
    result = result && (idx == expected_idx);
    count1++;
    }
    BitVecForeachIdx(&bv, bitval, i) {
    (void)bitval;
    count2++;
    ///              current bit during iteration. The type of `var` will be `bool`.
    ///
    #define BitVecForeach(bv, var) BitVecForeachIdx((bv), (var), UNPL(iter))
    
    ///

Share :