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:440:
}
void BitVecRemoveRange(BitVec *bv, u64 idx, u64 count) {
ValidateBitVec(bv);
if (idx >= bv->length) {- In
BitVec.c:1751:
}
BitVecRemoveRange(bv, pos, old_pattern->length);
for (u64 i = 0; i < new_pattern->length; i++) {- In
BitVec.c:1787:
break;
BitVecRemoveRange(bv, match_pos, old_pattern->length);
for (u64 i = 0; i < new_pattern->length; i++) { DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecRemoveRange\n");
BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
// Remove range from index 1 to 3 (3 bits)
BitVecRemoveRange(&bv, 1, 3);
// Check result: true, false, true (removed false, true, true)
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecRemoveRange edge cases\n");
BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc)); // Test remove 0 elements (should be no-op)
BitVecPush(&bv, true);
BitVecRemoveRange(&bv, 0, 0);
result = result && (BitVecLen(&bv) == 1); BitVecPush(&bv, i % 2 == 0);
}
BitVecRemoveRange(&bv, 0, 10);
result = result && (BitVecLen(&bv) == 0); 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
// Test NULL bitvec pointer - should abort
BitVecRemoveRange(NULL, 0, 1);
return false;
// Test removing beyond capacity limit - should abort
BitVecRemoveRange(&bv, SIZE_MAX, 1);
BitVecDeinit(&bv);
// Test remove range from empty bitvec - should abort
BitVecRemoveRange(&bv, 0, 1);
BitVecDeinit(&bv);
Last updated on