BitVecRemoveRange
Description
Remove multiple consecutive bits starting at a specific position. All bits after the removed range are shifted left.
Parameters
| Name | Direction | Description |
|---|---|---|
bv |
in,out | Bitvector to remove from. |
idx |
in | Starting position (0-based), in [0, length). |
count |
in | Number of bits to remove; idx + count must not exceed the length. |
Usage example (from documentation)
BitVecRemoveRange(&flags, 2, 3); // Remove 3 bits starting at position 2
Success
Returns to the caller. Bitvector length shrinks by count; bits previously at indices >= idx + count have shifted left by count. Capacity is unchanged.
Failure
Function cannot fail. An out-of-range idx + count is a caller bug and aborts via LOG_FATAL.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
BitVec.c:468:
}
void BitVecRemoveRange(BitVec *bv, u64 idx, u64 count) {
ValidateBitVec(bv);
if (idx >= bv->length) {- In
BitVec.c:1806:
}
BitVecRemoveRange(bv, pos, old_pattern->length);
for (u64 i = 0; i < new_pattern->length; i++) {- In
BitVec.c:1842:
break;
BitVecRemoveRange(bv, match_pos, old_pattern->length);
for (u64 i = 0; i < new_pattern->length; i++) {- In
Remove.c:115:
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecRemoveRange\n");
BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));- In
Remove.c:128:
// Remove range from index 1 to 3 (3 bits)
BitVecRemoveRange(&bv, 1, 3);
// Check result: true, false, true (removed false, true, true)
- In
Remove.c:328:
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecRemoveRange edge cases\n");
BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));- In
Remove.c:335:
// Test remove 0 elements (should be no-op)
BitVecPush(&bv, true);
BitVecRemoveRange(&bv, 0, 0);
result = result && (BitVecLen(&bv) == 1);- In
Remove.c:343:
BitVecPush(&bv, i % 2 == 0);
}
BitVecRemoveRange(&bv, 0, 10);
result = result && (BitVecLen(&bv) == 0);- In
Remove.c:350:
BitVecPush(&bv, i % 2 == 0);
}
BitVecRemoveRange(&bv, 1, 5); // Remove 5 elements starting at index 1
result = result && (BitVecLen(&bv) == 5); // Should have 5 elements left
- In
Remove.c:449:
// Test NULL bitvec pointer - should abort
BitVecRemoveRange(NULL, 0, 1);
return false;- In
Remove.c:462:
// Test removing beyond capacity limit - should abort
BitVecRemoveRange(&bv, SIZE_MAX, 1);
BitVecDeinit(&bv);- In
Remove.c:507:
// Test remove range from empty bitvec - should abort
BitVecRemoveRange(&bv, 0, 1);
BitVecDeinit(&bv);- In
Remove.c:520:
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecRemoveRange clamps oversized count\n");
BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));- In
Remove.c:531:
// Remove starting at idx 2 with a count far larger than what remains.
// Only 8 bits remain (indices 2..9), so result length must be 2.
BitVecRemoveRange(&bv, 2, 100);
bool result = (BitVecLen(&bv) == 2);- In
Remove.c:552:
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecRemoveRange clamp gap count\n");
BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));- In
Remove.c:562:
// idx=2, count=10: 8 bits remain from idx 2, so the result must be length 2.
BitVecRemoveRange(&bv, 2, 10);
bool result = (BitVecLen(&bv) == 2);- In
Remove.c:579:
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecRemoveRange shifts tail down\n");
BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));- In
Remove.c:591:
// Remove 3 bits starting at index 2 -> removes indices 2,3,4.
// Survivors: [1,0] ++ [1,0,1,1,0] = [1,0,1,0,1,1,0], length 7.
BitVecRemoveRange(&bv, 2, 3);
bool result = (BitVecLen(&bv) == 7);
Last updated on