BitVecMatches
Description
Match bitvector against pattern with wildcards. Wildcards allow flexible pattern matching where some positions can be “any bit”.
Parameters
| Name | Direction | Description |
|---|---|---|
bv |
in | Bitvector to match against |
pattern |
in | Pattern bitvector to match |
wildcard |
in | Wildcard bitvector (1 = wildcard position, 0 = exact match required) |
Usage example (from documentation)
bool matches = BitVecMatches(&data, &pattern, &wildcard);Success
true if pattern matches with wildcards
Failure
false if lengths disagree or any non-wildcard bit differs.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
BitVec.c:1857:
}
bool BitVecMatches(BitVec *bv, BitVec *pattern, BitVec *wildcard) {
ValidateBitVec(bv);
ValidateBitVec(pattern); DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecMatches(NULL, pattern, wildcard) - should fatal\n");
BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
BitVec wildcard = BitVecInit(ALLOCATOR_OF(&alloc)); BitVecPush(&pattern, true);
BitVecPush(&wildcard, false);
BitVecMatches(NULL, &pattern, &wildcard);
BitVecDeinit(&pattern);
BitVecDeinit(&wildcard); BitVecPush(&wildcard, false);
BitVecMatches(&source, NULL, &wildcard); // must abort
BitVecDeinit(&source); BitVecPush(&pattern, true);
BitVecMatches(&source, &pattern, NULL); // must abort
BitVecDeinit(&source); DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecMatches basic functionality\n");
BitVec source = BitVecInit(ALLOCATOR_OF(&alloc)); BitVecPush(&wildcard, false);
result = result && BitVecMatches(&source, &pattern, &wildcard);
BitVecDeinit(&source); BitVecPush(&wildcard, false);
result = result && (BitVecMatches(&source, &pattern, &wildcard) == false);
// Sanity: an all-wildcard mask must still match (proves we did not just
for (int i = 0; i < 4; i++)
BitVecPush(&wild_all, true);
result = result && (BitVecMatches(&source, &pattern, &wild_all) == true);
BitVecDeinit(&wild_all);
Last updated on