Skip to content
BitVecSuffixMatch

BitVecSuffixMatch

Description

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

Parameters

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

Usage example (from documentation)

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

Success

Index of matching pattern, or SIZE_MAX if no match

Failure

Returns SIZE_MAX when none of the candidate suffixes match bv.

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    u64 BitVecSuffixMatch(BitVec *bv, BitVecs *patterns) {
        ValidateBitVec(bv);
        if (!patterns) {
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        WriteFmt("Testing BitVecSuffixMatch basic functionality\n");
    
        BitVec  source   = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(p2, false);
    
        u64 match_idx = BitVecSuffixMatch(&source, &patterns);
        result        = result && (match_idx == 1);
    bool test_bitvec_suffix_match_null_source(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        WriteFmt("Testing BitVecSuffixMatch(NULL, patterns, 1) - should fatal\n");
        BitVecs vp = VecInitWithDeepCopy(NULL, BitVecDeinit, ALLOCATOR_OF(&alloc));
        BitVecPush(VecPtrAt(&vp, 0), true);
        BitVecs vp = VecInitWithDeepCopy(NULL, BitVecDeinit, ALLOCATOR_OF(&alloc));
        BitVecPush(VecPtrAt(&vp, 0), true);
        BitVecSuffixMatch(NULL, &vp);
        VecDeinit(&vp);
        DefaultAllocatorDeinit(&alloc);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        WriteFmt("Testing BitVecSuffixMatch(source, NULL, 1) - should fatal\n");
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&source, true);
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&source, true);
        BitVecSuffixMatch(&source, NULL);
        BitVecDeinit(&source);
        DefaultAllocatorDeinit(&alloc);
Last updated on