BitVecFindLast
- Function
- August 22, 2025
Table of Contents
BitVecFindLast
BitVecFindLast
Description
Find index of last occurrence of a specific bit value.
Parameters
Name | Direction | Description |
---|---|---|
bv | in | Bitvector to search in |
value | in | Bit value to find (true or false) |
Usage example (from documentation)
u64 index = BitVecFindLast(&flags, false);
Usage example (Cross-references)
- In
BitVec.c:400
:
ValidateBitVec(bv);
u64 pos = BitVecFindLast(bv, value);
if (pos != SIZE_MAX) {
BitVecRemove(bv, pos);
- In
BitVec.c:990
:
}
u64 BitVecFindLast(BitVec *bv, bool value) {
ValidateBitVec(bv);
// Test BitVecFindLast
result = result && (BitVecFindLast(&bv, true) == 7); // Last true at index 7
result = result && (BitVecFindLast(&bv, false) == 6); // Last false at index 6
// Test BitVecFindLast
result = result && (BitVecFindLast(&bv, true) == 7); // Last true at index 7
result = result && (BitVecFindLast(&bv, false) == 6); // Last false at index 6
// Test with all same values
}
result = result && (BitVecFind(&bv, true) == 0);
result = result && (BitVecFindLast(&bv, true) == 4);
result = result && (BitVecFind(&bv, false) == SIZE_MAX);
result = result && (BitVecFindLast(&bv, false) == SIZE_MAX);
result = result && (BitVecFindLast(&bv, true) == 4);
result = result && (BitVecFind(&bv, false) == SIZE_MAX);
result = result && (BitVecFindLast(&bv, false) == SIZE_MAX);
BitVecDeinit(&bv);
result = result && (BitVecFind(&bv, true) == SIZE_MAX);
result = result && (BitVecFind(&bv, false) == SIZE_MAX);
result = result && (BitVecFindLast(&bv, true) == SIZE_MAX);
result = result && (BitVecFindLast(&bv, false) == SIZE_MAX);
result = result && (BitVecFind(&bv, false) == SIZE_MAX);
result = result && (BitVecFindLast(&bv, true) == SIZE_MAX);
result = result && (BitVecFindLast(&bv, false) == SIZE_MAX);
// Test single element
BitVecPush(&bv, true);
result = result && (BitVecFind(&bv, true) == 0);
result = result && (BitVecFindLast(&bv, true) == 0);
result = result && (BitVecFind(&bv, false) == SIZE_MAX);
result = result && (BitVecFindLast(&bv, false) == SIZE_MAX);
result = result && (BitVecFindLast(&bv, true) == 0);
result = result && (BitVecFind(&bv, false) == SIZE_MAX);
result = result && (BitVecFindLast(&bv, false) == SIZE_MAX);
// Test with large bitvector
}
result = result && (BitVecFind(&bv, true) == 500);
result = result && (BitVecFindLast(&bv, true) == 999);
BitVecDeinit(&bv);
// Test BitVecFind and BitVecFindLast functions
bool test_bitvec_find_functions(void) {
printf("Testing BitVecFind and BitVecFindLast functions\n");
BitVec bv = BitVecInit();
// Test finding last true (should be at index 5)
result = result && (BitVecFindLast(&bv, true) == 5);
// Test finding last false (should be at index 7)
// Test finding last false (should be at index 7)
result = result && (BitVecFindLast(&bv, false) == 7);
// Test with all same values
result = result && (BitVecFind(&bv, true) == 0);
result = result && (BitVecFindLast(&bv, true) == 2);
result = result && (BitVecFind(&bv, false) == SIZE_MAX);
result = result && (BitVecFindLast(&bv, false) == SIZE_MAX);
result = result && (BitVecFindLast(&bv, true) == 2);
result = result && (BitVecFind(&bv, false) == SIZE_MAX);
result = result && (BitVecFindLast(&bv, false) == SIZE_MAX);
BitVecDeinit(&bv);
result = result && (BitVecFind(&bv, true) == SIZE_MAX);
result = result && (BitVecFind(&bv, false) == SIZE_MAX);
result = result && (BitVecFindLast(&bv, true) == SIZE_MAX);
result = result && (BitVecFindLast(&bv, false) == SIZE_MAX);
result = result && (BitVecFind(&bv, false) == SIZE_MAX);
result = result && (BitVecFindLast(&bv, true) == SIZE_MAX);
result = result && (BitVecFindLast(&bv, false) == SIZE_MAX);
// Test single element
BitVecPush(&bv, true);
result = result && (BitVecFind(&bv, true) == 0);
result = result && (BitVecFindLast(&bv, true) == 0);
result = result && (BitVecFind(&bv, false) == SIZE_MAX);
result = result && (BitVecFindLast(&bv, false) == SIZE_MAX);
result = result && (BitVecFindLast(&bv, true) == 0);
result = result && (BitVecFind(&bv, false) == SIZE_MAX);
result = result && (BitVecFindLast(&bv, false) == SIZE_MAX);
// Test with large bitvector
}
result = result && (BitVecFind(&bv, true) == 500);
result = result && (BitVecFindLast(&bv, true) == 999);
BitVecDeinit(&bv);