BitVecStartsWith
Description
Check if bitvector starts with the given bit pattern.
Parameters
| Name | Direction | Description |
|---|---|---|
bv |
in | Bitvector to check |
prefix |
in | Pattern to match at the beginning |
Usage example (from documentation)
bool starts = BitVecStartsWith(&flags, &pattern);Success
true if bitvector starts with the pattern
Failure
false if the prefix is longer than bv or any bit differs.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
BitVec.c:1660:
}
bool BitVecStartsWith(BitVec *bv, BitVec *prefix) {
ValidateBitVec(bv);
ValidateBitVec(prefix);- In
BitVec.c:1894:
VecForeachPtrIdx(patterns, pattern, i) {
if (BitVecStartsWith(bv, pattern)) {
return i;
} DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecStartsWith basic functionality\n");
BitVec source = BitVecInit(ALLOCATOR_OF(&alloc)); BitVecPush(&prefix, false);
result = result && BitVecStartsWith(&source, &prefix);
// Test non-matching prefix: 101
BitVecPush(&prefix, true);
result = result && !BitVecStartsWith(&source, &prefix);
BitVecDeinit(&source); DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecStartsWith edge cases\n");
BitVec source = BitVecInit(ALLOCATOR_OF(&alloc)); // Test empty prefix (should always match)
BitVecPush(&source, true);
result = result && BitVecStartsWith(&source, &prefix);
// Test prefix longer than source
BitVecPush(&prefix, true);
BitVecPush(&prefix, false);
result = result && !BitVecStartsWith(&source, &prefix);
// Test equal length
BitVecPush(&prefix, true);
BitVecPush(&prefix, false);
result = result && BitVecStartsWith(&source, &prefix);
BitVecDeinit(&source); DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecStartsWith(NULL, prefix) - should fatal\n");
BitVec prefix = BitVecInit(ALLOCATOR_OF(&alloc));
BitVecPush(&prefix, true); BitVec prefix = BitVecInit(ALLOCATOR_OF(&alloc));
BitVecPush(&prefix, true);
BitVecStartsWith(NULL, &prefix);
BitVecDeinit(&prefix);
DefaultAllocatorDeinit(&alloc); DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecStartsWith(source, NULL) - should fatal\n");
BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
BitVecPush(&source, true); BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
BitVecPush(&source, true);
BitVecStartsWith(&source, NULL);
BitVecDeinit(&source);
DefaultAllocatorDeinit(&alloc);
Last updated on