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
| Name | Direction | Description |
|---|---|---|
bv |
in,out | Bitvector to iterate over. |
var |
in | Name of variable to be used which’ll contain bit value at iterated index idx |
idx |
in | Name of variable to be used for iterating over indices. |
Success
Loop body runs once per bit, with var holding the bit and idx its position.
Failure
Loop body never executes when bv is empty; validator aborts on corrupted magic.
Usage example (Cross-references)
Usage examples (Cross-references)
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecForeachIdx macro\n");
BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc)); 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++; DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecForeachIdx macro\n");
BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc)); 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++;- In
Foreach.h:70:
/// TAGS: BitVec, Foreach, Forward, Iteration
///
#define BitVecForeach(bv, var) BitVecForeachIdx((bv), (var), UNPL(iter))
///
Last updated on