BitVecFind
- Function
- August 22, 2025
Table of Contents
BitVecFind
BitVecFind
Description
Find index of first 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 = BitVecFind(&flags, true);
if (index != SIZE_MAX) { /* found at index */ }
Usage example (Cross-references)
- In
BitVec.c:388
:
ValidateBitVec(bv);
u64 pos = BitVecFind(bv, value);
if (pos != SIZE_MAX) {
BitVecRemove(bv, pos);
- In
BitVec.c:979
:
// Missing Access functions implementation
u64 BitVecFind(BitVec *bv, bool value) {
ValidateBitVec(bv);
- In
BitVec.c:1020
:
bool BitVecAny(BitVec *bv, bool value) {
ValidateBitVec(bv);
return BitVecFind(bv, value) != SIZE_MAX;
}
// Test BitVecFind functions (Find, FindLast)
bool test_bitvec_find_functions(void) {
printf("Testing BitVecFind functions\n");
BitVec bv = BitVecInit();
// Test BitVecFind
result = result && (BitVecFind(&bv, true) == 1); // First true at index 1
result = result && (BitVecFind(&bv, false) == 0); // First false at index 0
// Test BitVecFind
result = result && (BitVecFind(&bv, true) == 1); // First true at index 1
result = result && (BitVecFind(&bv, false) == 0); // First false at index 0
// Test BitVecFindLast
BitVecPush(&bv, true);
}
result = result && (BitVecFind(&bv, true) == 0);
result = result && (BitVecFindLast(&bv, true) == 4);
result = result && (BitVecFind(&bv, false) == SIZE_MAX);
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);
// Edge case tests for Find functions
bool test_bitvec_find_edge_cases(void) {
printf("Testing BitVecFind edge cases\n");
BitVec bv = BitVecInit();
// Test empty bitvector
result = result && (BitVecFind(&bv, true) == SIZE_MAX);
result = result && (BitVecFind(&bv, false) == SIZE_MAX);
result = result && (BitVecFindLast(&bv, true) == SIZE_MAX);
// Test empty bitvector
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);
// 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 && (BitVecFind(&bv, true) == 0);
result = result && (BitVecFindLast(&bv, true) == 0);
result = result && (BitVecFind(&bv, false) == SIZE_MAX);
result = result && (BitVecFindLast(&bv, false) == SIZE_MAX);
BitVecPush(&bv, i == 500 || i == 999); // Only indices 500 and 999 are true
}
result = result && (BitVecFind(&bv, true) == 500);
result = result && (BitVecFindLast(&bv, true) == 999);
// Deadend tests - testing NULL pointers and invalid conditions that should cause fatal errors
bool test_bitvec_find_deadend_tests(void) {
printf("Testing BitVecFind deadend scenarios\n");
// This should cause LOG_FATAL and terminate the program
// This should cause LOG_FATAL and terminate the program
BitVecFind(NULL, true);
return true; // Should never reach here
// Test BitVecFind and BitVecFindLast functions
bool test_bitvec_find_functions(void) {
printf("Testing BitVecFind and BitVecFindLast functions\n");
BitVec bv = BitVecInit();
// Test finding first true (should be at index 0)
result = result && (BitVecFind(&bv, true) == 0);
// Test finding first false (should be at index 1)
// Test finding first false (should be at index 1)
result = result && (BitVecFind(&bv, false) == 1);
// Test finding last true (should be at index 5)
BitVecPush(&bv, true);
result = result && (BitVecFind(&bv, true) == 0);
result = result && (BitVecFindLast(&bv, true) == 2);
result = result && (BitVecFind(&bv, false) == SIZE_MAX);
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);
// Edge case tests for Find functions
bool test_bitvec_find_edge_cases(void) {
printf("Testing BitVecFind edge cases\n");
BitVec bv = BitVecInit();
// Test empty bitvector
result = result && (BitVecFind(&bv, true) == SIZE_MAX);
result = result && (BitVecFind(&bv, false) == SIZE_MAX);
result = result && (BitVecFindLast(&bv, true) == SIZE_MAX);
// Test empty bitvector
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);
// 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 && (BitVecFind(&bv, true) == 0);
result = result && (BitVecFindLast(&bv, true) == 0);
result = result && (BitVecFind(&bv, false) == SIZE_MAX);
result = result && (BitVecFindLast(&bv, false) == SIZE_MAX);
BitVecPush(&bv, i == 500 || i == 999); // Only indices 500 and 999 are true
}
result = result && (BitVecFind(&bv, true) == 500);
result = result && (BitVecFindLast(&bv, true) == 999);
// Deadend tests - testing NULL pointers and invalid conditions that should cause fatal errors
bool test_bitvec_find_deadend_tests(void) {
printf("Testing BitVecFind deadend scenarios\n");
// This should cause LOG_FATAL and terminate the program
// This should cause LOG_FATAL and terminate the program
BitVecFind(NULL, true);
return true; // Should never reach here