BitVecInsertMultiple
Description
Insert all bits from another bitvector at a specific position. All existing bits at and after the position are shifted right.
Parameters
| Name | Direction | Description |
|---|---|---|
bv |
in,out | Bitvector to insert into. |
idx |
in | Position to insert at (0-based), in [0, length]. |
other |
in | Bitvector whose bits to insert. |
Usage example (from documentation)
BitVecInsertMultiple(&flags, 2, &other_flags);Success
Returns true. Bitvector length grows by other->length; the range [idx, idx + other->length) mirrors the bits of other in order; previous bits at and after idx have shifted right by other->length. other is untouched.
Failure
Returns false on allocation failure when capacity must grow. The bitvector is unchanged.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Insert.h:47:
#define BitVecMustInsertMultiple(bv, idx, other) \
do { \
if (!BitVecInsertMultiple((bv), (idx), (other))) { \
LOG_FATAL("BitVecMustInsertMultiple failed"); \
} \- In
BitVec.c:392:
}
bool BitVecInsertMultiple(BitVec *bv, u64 idx, BitVec *other) {
ValidateBitVec(bv);
ValidateBitVec(other);- In
Insert.c:134:
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecInsertMultiple\n");
BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));- In
Insert.c:149:
// Insert multiple bits from source
BitVecInsertMultiple(&bv, 1, &source);
// Check result: true, true, true, true, false
- In
Insert.c:252:
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecInsertMultiple edge cases\n");
BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));- In
Insert.c:260:
// Test inserting empty bitvec
BitVecInsertMultiple(&bv, 0, &empty);
result = result && (BitVecLen(&bv) == 0);- In
Insert.c:265:
// Test inserting single bit bitvec
BitVecPush(&source, true);
BitVecInsertMultiple(&bv, 0, &source);
result = result && (BitVecLen(&bv) == 1) && (BitVecGet(&bv, 0) == true);- In
Insert.c:273:
BitVecPush(&source, false);
}
BitVecInsertMultiple(&bv, 1, &source);
result = result && (BitVecLen(&bv) == 501);
result = result && (BitVecGet(&bv, 1) == false);- In
Insert.c:384:
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecInsertMultiple shifts existing tail bits\n");
BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));- In
Insert.c:399:
// Insert other at index 1 -> [1, 1, 1, 0, 1]
BitVecInsertMultiple(&bv, 1, &other);
bool result = (BitVecLen(&bv) == 5);- In
Insert.c:429:
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecInsertMultiple NULL bv validation\n");
BitVec other = BitVecInit(ALLOCATOR_OF(&alloc));- In
Insert.c:434:
BitVecPush(&other, true);
BitVecInsertMultiple(NULL, 0, &other);
// If we reach here, validation did not abort.
- In
Insert.c:446:
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecInsertMultiple NULL other validation\n");
BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));- In
Insert.c:451:
BitVecPush(&bv, true);
BitVecInsertMultiple(&bv, 0, NULL);
// If we reach here, validation did not abort.
Last updated on