BitVecInsert
Description
Insert a bit at given index in bitvector. Shifts all bits at and after the index to the right.
Parameters
| Name | Direction | Description |
|---|---|---|
bv |
in,out | Bitvector to insert bit into. |
idx |
in | Index at which to insert bit (0-based), in [0, length]. |
value |
in | Bit value to insert (true/false). |
Usage example (from documentation)
BitVecInsert(&flags, 5, true);Success
Returns true. Bitvector length grows by one; bit at index idx is now value; previous bits at and after idx have shifted right by one.
Failure
Returns false on allocation failure. The bitvector is unchanged.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
BitVec.c:319:
}
bool BitVecInsert(BitVec *bitvec, u64 idx, bool value) {
ValidateBitVec(bitvec);
if (idx > bitvec->length) {- In
BitVec.c:1754:
for (u64 i = 0; i < new_pattern->length; i++) {
if (!BitVecInsert(bv, pos + i, BitVecGet(new_pattern, i))) {
return false;
}- In
BitVec.c:1790:
for (u64 i = 0; i < new_pattern->length; i++) {
if (!BitVecInsert(bv, match_pos + i, BitVecGet(new_pattern, i))) {
return replacements;
} DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecInsert (single bit)\n");
BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
// Insert at index 0 (empty bitvector)
BitVecInsert(&bv, 0, true);
// Check first bit
// Insert at the end
BitVecInsert(&bv, 1, false);
// Check bits
// Insert in the middle
BitVecInsert(&bv, 1, true);
// Check all bits
- In
Insert.h:98:
#define BitVecMustInsert(bv, idx, value) \
do { \
if (!BitVecInsert((bv), (idx), (value))) { \
LOG_FATAL("BitVecMustInsert failed"); \
} \
Last updated on