Skip to content
BitVecFindLastPattern

BitVecFindLastPattern

Description

Find last occurrence of a bit pattern in the bitvector.

Parameters

Name Direction Description
bv in Bitvector to search in
pattern in Pattern to search for

Usage example (from documentation)

  u64 index = BitVecFindLastPattern(&flags, &pattern);

Success

Index of last occurrence, or SIZE_MAX if not found

Failure

Returns SIZE_MAX when the pattern is absent or longer than bv.

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    u64 BitVecFindLastPattern(BitVec *bv, BitVec *pattern) {
        ValidateBitVec(bv);
        ValidateBitVec(pattern);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        WriteFmt("Testing BitVecFindLastPattern function\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&pattern, false);
    
        u64 index = BitVecFindLastPattern(&source, &pattern);
        result    = result && (index == 6); // Last occurrence of "10" should be at index 6
        BitVecPush(&pattern, true);
    
        index  = BitVecFindLastPattern(&source, &pattern);
        result = result && (index == 2); // Only occurrence at index 2
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        WriteFmt("Testing BitVecFindLastPattern(NULL, pattern) - should fatal\n");
    
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&pattern, true);
    
        BitVecFindLastPattern(NULL, &pattern); // Should cause LOG_FATAL
    
        BitVecDeinit(&pattern);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        WriteFmt("Testing BitVecFindLastPattern(source, NULL) - should fatal\n");
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&source, false);
    
        BitVecFindLastPattern(&source, NULL); // Should cause LOG_FATAL
    
        BitVecDeinit(&source);
Last updated on