BitVecPrefixMatch

Table of Contents

BitVecPrefixMatch

Description

Match bitvector against an array of prefix patterns. Returns the index of the first matching prefix.

Parameters

NameDirectionDescription
bvinBitVec to check
patternsinVec(BitVec) to check prefices against

Usage example (from documentation)

  BitVec prefixes[3] = { pattern1, pattern2, pattern3 };
  u64 match = BitVecPrefixMatch(&data, prefixes, 3);

Usage example (Cross-references)

    }
    
    u64 BitVecPrefixMatch(BitVec *bv, BitVecs *patterns) {
    ValidateBitVec(bv);
    if (!patterns) {
    // BitVecPrefixMatch tests
    bool test_bitvec_prefix_match_basic(void) {
    WriteFmt("Testing BitVecPrefixMatch basic functionality\n");
    
    BitVec source = BitVecInit();
    BitVecPush(&patterns[2], true);
    
    u64 match_idx = BitVecPrefixMatch(&source, patterns, 3);
    result        = result && (match_idx == 1);
    
    bool test_bitvec_prefix_match_null_source(void) {
    WriteFmt("Testing BitVecPrefixMatch(NULL, patterns, 1) - should fatal\n");
    BitVec patterns[1] = {BitVecInit()};
    BitVecPush(&patterns[0], true);
    BitVec patterns[1] = {BitVecInit()};
    BitVecPush(&patterns[0], true);
    BitVecPrefixMatch(NULL, patterns, 1);
    BitVecDeinit(&patterns[0]);
    return true;
    
    bool test_bitvec_prefix_match_null_patterns(void) {
    WriteFmt("Testing BitVecPrefixMatch(source, NULL, 1) - should fatal\n");
    BitVec source = BitVecInit();
    BitVecPush(&source, true);
    BitVec source = BitVecInit();
    BitVecPush(&source, true);
    BitVecPrefixMatch(&source, NULL, 1);
    BitVecDeinit(&source);
    return true;
    
    bool test_bitvec_prefix_match_null_source(void) {
    WriteFmt("Testing BitVecPrefixMatch(NULL, patterns, 1) - should fatal\n");
    BitVecs vp = VecInitWithDeepCopy(NULL, BitVecDeinit);
    BitVecPush(VecPtrAt(&vp, 0), true);
    BitVecs vp = VecInitWithDeepCopy(NULL, BitVecDeinit);
    BitVecPush(VecPtrAt(&vp, 0), true);
    BitVecPrefixMatch(NULL, &vp);
    VecDeinit(&vp);
    return true;
    
    bool test_bitvec_prefix_match_null_patterns(void) {
    WriteFmt("Testing BitVecPrefixMatch(source, NULL, 1) - should fatal\n");
    BitVec source = BitVecInit();
    BitVecPush(&source, true);
    BitVec source = BitVecInit();
    BitVecPush(&source, true);
    BitVecPrefixMatch(&source, NULL);
    BitVecDeinit(&source);
    return true;
    // BitVecPrefixMatch tests
    bool test_bitvec_prefix_match_basic(void) {
    WriteFmt("Testing BitVecPrefixMatch basic functionality\n");
    
    BitVec  source   = BitVecInit();
    BitVecPush(p2, true);
    
    u64 match_idx = BitVecPrefixMatch(&source, &patterns);
    result        = result && (match_idx == 1);

Share :

Related Posts

BitVecRFindPattern

BitVecRFindPattern Description Search for a pattern starting from a specific position (reverse search).

Read More

BitVecFuzzyMatch

BitVecFuzzyMatch Description Fuzzy pattern matching allowing up to N mismatches. Useful for approximate pattern matching with error tolerance.

Read More

BitVecRegexMatch

BitVecRegexMatch Description Simple regex-style pattern matching for bitvectors. Supports basic patterns: ‘*’ (any sequence), ‘?’ (0 or 1), ‘[01]’ (literal).

Read More