Skip to content
BitVecPrefixMatch

BitVecPrefixMatch

BitVecPrefixMatch

Description

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

Parameters

Name Direction Description
bv in BitVec to check
patterns in Vec(BitVec) to check prefices against

Usage example (from documentation)

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

Returns

Index of matching pattern, or SIZE_MAX if no match

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    u64 BitVecPrefixMatch(BitVec *bv, BitVecs *patterns) {
        ValidateBitVec(bv);
        if (!patterns) {
    
    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(&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;
    // 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);
Last updated on