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);Success
Returns the zero-based index of the last bit equal to value. The bitvector is not modified.
Failure
Returns SIZE_MAX when no bit matches (including an empty bitvector). The bitvector is not modified.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
BitVec.c:507:
ValidateBitVec(bv);
u64 pos = BitVecFindLast(bv, value);
if (pos != SIZE_MAX) {
BitVecRemove(bv, pos);- In
BitVec.c:1241:
}
u64 BitVecFindLast(const BitVec *bv, bool value) {
ValidateBitVec(bv); // would let the NULL flow into `bv->length` instead.
bool test_find_last_null_bv_aborts(void) {
WriteFmt("Testing BitVecFindLast with NULL bitvector\n");
BitVecFindLast(NULL, true);
return true; // Should never reach here.
bool test_find_last_null_bv_aborts(void) {
WriteFmt("Testing BitVecFindLast with NULL bitvector\n");
BitVecFindLast(NULL, true);
return true; // Should never reach here.
}
// 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);
Last updated on