BitVecContainsAt
Description
Check if bitvector contains the given pattern at a specific position.
Parameters
| Name | Direction | Description |
|---|---|---|
bv |
in | Bitvector to check |
pattern |
in | Pattern to match |
idx |
in | Position to check at |
Usage example (from documentation)
bool at_pos = BitVecContainsAt(&flags, &pattern, 5);Success
true if pattern matches at the given position
Failure
false if idx is out of range or any bit differs at that offset.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
BitVec.c:1258:
for (u64 i = 0; i <= bv->length - pattern->length; i++) {
if (BitVecContainsAt(bv, pattern, i)) {
return i;
}- In
BitVec.c:1275:
// `i < bv->length` is the underflow guard, matching BitVecFindLast.
for (u64 i = bv->length - pattern->length; i < bv->length; i--) {
if (BitVecContainsAt(bv, pattern, i)) {
return i;
}- In
BitVec.c:1299:
for (u64 i = 0; i <= bv->length - pattern->length && found_count < max_results; i++) {
if (BitVecContainsAt(bv, pattern, i)) {
results[found_count] = i;
found_count++;- In
BitVec.c:1320:
for (u64 i = 0; i <= bv->length - pattern->length; i++) {
if (BitVecContainsAt(bv, pattern, i)) {
size idx = (size)i;
if (!VecPushBackR(out, idx))- In
BitVec.c:1668:
}
return BitVecContainsAt(bv, prefix, 0);
}- In
BitVec.c:1680:
u64 start_pos = bv->length - suffix->length;
return BitVecContainsAt(bv, suffix, start_pos);
}- In
BitVec.c:1683:
}
bool BitVecContainsAt(BitVec *bv, BitVec *pattern, u64 idx) {
ValidateBitVec(bv);
ValidateBitVec(pattern);- In
BitVec.c:1713:
u64 count = 0;
for (u64 i = 0; i <= bv->length - pattern->length; i++) {
if (BitVecContainsAt(bv, pattern, i)) {
count++;
}- In
BitVec.c:1733:
for (u64 i = start + 1; i > search_end; i--) {
u64 pos = i - 1;
if (BitVecContainsAt(bv, pattern, pos)) {
return pos;
}- In
BitVec.c:1776:
if (search_pos + old_pattern->length <= bv->length) {
for (u64 i = search_pos; i <= bv->length - old_pattern->length; i++) {
if (BitVecContainsAt(bv, old_pattern, i)) {
match_pos = i;
found = true; DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecContainsAt basic functionality\n");
BitVec source = BitVecInit(ALLOCATOR_OF(&alloc)); BitVecPush(&pattern, true);
result = result && BitVecContainsAt(&source, &pattern, 1); // Should match
result = result && !BitVecContainsAt(&source, &pattern, 0); // Should not match
result = result && BitVecContainsAt(&source, &pattern, 3); // Should match
result = result && BitVecContainsAt(&source, &pattern, 1); // Should match
result = result && !BitVecContainsAt(&source, &pattern, 0); // Should not match
result = result && BitVecContainsAt(&source, &pattern, 3); // Should match
result = result && BitVecContainsAt(&source, &pattern, 1); // Should match
result = result && !BitVecContainsAt(&source, &pattern, 0); // Should not match
result = result && BitVecContainsAt(&source, &pattern, 3); // Should match
BitVecDeinit(&source); DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecContainsAt edge cases\n");
BitVec source = BitVecInit(ALLOCATOR_OF(&alloc)); BitVecPush(&pattern, true);
result = result && !BitVecContainsAt(&source, &pattern, 0); // Pattern too long
BitVecDeinit(&source); DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecContainsAt(NULL, pattern, 0) - should fatal\n");
BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
BitVecPush(&pattern, true); BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
BitVecPush(&pattern, true);
BitVecContainsAt(NULL, &pattern, 0);
BitVecDeinit(&pattern);
DefaultAllocatorDeinit(&alloc); DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecContainsAt(source, NULL, 0) - should fatal\n");
BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
BitVecPush(&source, true); BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
BitVecPush(&source, true);
BitVecContainsAt(&source, NULL, 0);
BitVecDeinit(&source);
DefaultAllocatorDeinit(&alloc);
Last updated on