BitVecRemoveAll
Description
Remove all occurrences of a specific bit value.
Parameters
| Name | Direction | Description |
|---|---|---|
bv |
in,out | Bitvector to remove from. |
value |
in | Bit value to remove (true or false). |
Usage example (from documentation)
u64 removed = BitVecRemoveAll(&flags, true);Success
Returns the count of bits removed. Bitvector length shrinks by the returned count; remaining bits are compacted to the front in their original relative order.
Failure
Returns 0 when no bit equal to value exists. The bitvector is unchanged.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
BitVec.c:488:
}
u64 BitVecRemoveAll(BitVec *bv, bool value) {
ValidateBitVec(bv); DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecRemoveAll\n");
BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
// Remove all false bits
u64 removed_count = BitVecRemoveAll(&bv, false);
// Check result: true, true, true (all false bits removed)
// Try to remove all false bits again (should return 0)
removed_count = BitVecRemoveAll(&bv, false);
result = result && (removed_count == 0) && (BitVecLen(&bv) == 3);
// Remove all true bits
removed_count = BitVecRemoveAll(&bv, true);
result = result && (removed_count == 3) && (BitVecLen(&bv) == 0); DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecRemoveAll edge cases\n");
BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
// Test remove all from empty bitvec
u64 count = BitVecRemoveAll(&bv, true);
result = result && (count == 0) && (BitVecLen(&bv) == 0); BitVecPush(&bv, true);
BitVecPush(&bv, true);
count = BitVecRemoveAll(&bv, false);
result = result && (count == 0) && (BitVecLen(&bv) == 2); BitVecPush(&bv, true);
}
count = BitVecRemoveAll(&bv, true);
result = result && (count == 100) && (BitVecLen(&bv) == 0); BitVecPush(&bv, i % 2 == 0);
}
count = BitVecRemoveAll(&bv, false); // Remove odds
result = result && (count == 500) && (BitVecLen(&bv) == 500);
Last updated on