BitVecFuzzyMatch
Description
Fuzzy pattern matching allowing up to N mismatches. Useful for approximate pattern matching with error tolerance.
Parameters
| Name | Direction | Description |
|---|---|---|
bv |
in | Bitvector to search in |
pattern |
in | Pattern to search for |
max_errors |
in | Maximum number of mismatches allowed |
Usage example (from documentation)
u64 index = BitVecFuzzyMatch(&data, &pattern, 2); // Allow 2 errors
Success
Index of first fuzzy match, or SIZE_MAX if not found
Failure
Returns SIZE_MAX when no window of bv matches pattern within max_errors.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
BitVec.c:1878:
}
u64 BitVecFuzzyMatch(BitVec *bv, BitVec *pattern, u64 max_errors) {
ValidateBitVec(bv);
ValidateBitVec(pattern); BitVecPush(&pattern, true);
BitVecFuzzyMatch(NULL, &pattern, 0); // must abort
BitVecDeinit(&pattern); BitVecPush(&source, true);
BitVecFuzzyMatch(&source, NULL, 0); // must abort
BitVecDeinit(&source); DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecFuzzyMatch basic functionality\n");
BitVec source = BitVecInit(ALLOCATOR_OF(&alloc)); BitVecPush(&pattern, true);
u64 pos = BitVecFuzzyMatch(&source, &pattern, 0);
result = result && (pos == 6);
// Test with 1 error allowed
pos = BitVecFuzzyMatch(&source, &pattern, 1);
result = result && (pos == 0); // Should match 110 with 1 error
}
result = result && (BitVecFuzzyMatch(&source, &pattern, 0) == 0);
BitVecDeinit(&source); // Window [4,6] = 011 -> 1 error <= 1 (first acceptable window).
// Window [0,2] = 000 -> 3 errors; window [5,7] = 111 -> 0 errors.
result = result && (BitVecFuzzyMatch(&source, &pattern, 1) == 4);
// Exact match still found at index 5 when no errors are allowed.
result = result && (BitVecFuzzyMatch(&source, &pattern, 0) == 5); result = result && (BitVecFuzzyMatch(&source, &pattern, 1) == 4);
// Exact match still found at index 5 when no errors are allowed.
result = result && (BitVecFuzzyMatch(&source, &pattern, 0) == 5);
BitVecDeinit(&source); BitVecPush(&pattern, true);
bool result = (BitVecFuzzyMatch(&source, &pattern, 0) == SIZE_MAX);
BitVecDeinit(&source);
Last updated on