BitVecFindAllPattern

Table of Contents

BitVecFindAllPattern

Description

Find all occurrences of a bit pattern in the bitvector. Results array must be pre-allocated with sufficient space.

Parameters

NameDirectionDescription
bvinBitvector to search in
patterninPattern to search for
resultsoutArray to store found indices
max_resultsinMaximum number of results to store

Usage example (from documentation)

  u64 indices[10];
  u64 count = BitVecFindAllPattern(&flags, &pattern, indices, 10);

Usage example (Cross-references)

    }
    
    u64 BitVecFindAllPattern(BitVec *bv, BitVec *pattern, size *results, u64 max_results) {
    ValidateBitVec(bv);
    ValidateBitVec(pattern);
    // Test BitVecFindAllPattern function
    bool test_bitvec_find_all_pattern(void) {
    WriteFmt("Testing BitVecFindAllPattern function\n");
    
    BitVec source  = BitVecInit();
    
    size results[10];
    u64  count = BitVecFindAllPattern(&source, &pattern, results, 10);
    
    // Should find pattern at indices 0, 2, 4, 6, 8
    
    // Test with limited results array
    u64 count_limited = BitVecFindAllPattern(&source, &pattern, results, 3);
    result            = result && (count_limited == 3); // Should only return first 3 matches
    BitVecPush(&pattern, false);
    
    count  = BitVecFindAllPattern(&source, &pattern, results, 10);
    result = result && (count == 3); // Should find at 0, 3, 6
    BitVecPush(&pattern, true);
    
    u64 count = BitVecFindAllPattern(&source, &pattern, results, 1);
    result    = result && (count == 1);
    result    = result && (results[0] == 0);
    // Test finding all occurrences in large data
    size results[200];
    u64  count = BitVecFindAllPattern(&source, &pattern, results, 200);
    result     = result && (count > 0); // Should find at least some patterns
    // Deadend test 5: BitVecFindAllPattern with NULL source
    bool test_bitvec_find_all_pattern_null_source(void) {
    WriteFmt("Testing BitVecFindAllPattern(NULL, pattern, results, 10) - should fatal\n");
    
    size results[10];
    
    // Don't create pattern BitVec since we're testing NULL source validation
    BitVecFindAllPattern(NULL, (BitVec *)0x1, results, 10); // Should cause LOG_FATAL
    
    return true;
    // Deadend test 6: BitVecFindAllPattern with NULL pattern
    bool test_bitvec_find_all_pattern_null_pattern(void) {
    WriteFmt("Testing BitVecFindAllPattern(source, NULL, results, 10) - should fatal\n");
    
    BitVec source = BitVecInit();
    BitVecPush(&source, false);
    
    BitVecFindAllPattern(&source, NULL, results, 10); // Should cause LOG_FATAL
    
    BitVecDeinit(&source);
    // Deadend test 7: BitVecFindAllPattern with NULL results
    bool test_bitvec_find_all_pattern_null_results(void) {
    WriteFmt("Testing BitVecFindAllPattern(source, pattern, NULL, 10) - should fatal\n");
    
    BitVec source  = BitVecInit();
    BitVecPush(&pattern, true);
    
    BitVecFindAllPattern(&source, &pattern, NULL, 10); // Should cause LOG_FATAL
    
    BitVecDeinit(&source);
    // Deadend test 8: BitVecFindAllPattern with zero max_results
    bool test_bitvec_find_all_pattern_zero_max_results(void) {
    WriteFmt("Testing BitVecFindAllPattern(source, pattern, results, 0) - should fatal\n");
    
    BitVec source  = BitVecInit();
    BitVecPush(&pattern, true);
    
    BitVecFindAllPattern(&source, &pattern, results, 0); // Should cause LOG_FATAL
    
    BitVecDeinit(&source);
    // Deadend test 5: BitVecFindAllPattern with NULL source
    bool test_bitvec_find_all_pattern_null_source(void) {
    WriteFmt("Testing BitVecFindAllPattern(NULL, pattern, results, 10) - should fatal\n");
    
    size results[10];
    
    // Don't create pattern BitVec since we're testing NULL source validation
    BitVecFindAllPattern(NULL, (BitVec *)0x1, results, 10); // Should cause LOG_FATAL
    
    return true;
    // Deadend test 6: BitVecFindAllPattern with NULL pattern
    bool test_bitvec_find_all_pattern_null_pattern(void) {
    WriteFmt("Testing BitVecFindAllPattern(source, NULL, results, 10) - should fatal\n");
    
    BitVec source = BitVecInit();
    BitVecPush(&source, false);
    
    BitVecFindAllPattern(&source, NULL, results, 10); // Should cause LOG_FATAL
    
    BitVecDeinit(&source);
    // Deadend test 7: BitVecFindAllPattern with NULL results
    bool test_bitvec_find_all_pattern_null_results(void) {
    WriteFmt("Testing BitVecFindAllPattern(source, pattern, NULL, 10) - should fatal\n");
    
    BitVec source  = BitVecInit();
    BitVecPush(&pattern, true);
    
    BitVecFindAllPattern(&source, &pattern, NULL, 10); // Should cause LOG_FATAL
    
    BitVecDeinit(&source);
    // Deadend test 8: BitVecFindAllPattern with zero max_results
    bool test_bitvec_find_all_pattern_zero_max_results(void) {
    WriteFmt("Testing BitVecFindAllPattern(source, pattern, results, 0) - should fatal\n");
    
    BitVec source  = BitVecInit();
    BitVecPush(&pattern, true);
    
    BitVecFindAllPattern(&source, &pattern, results, 0); // Should cause LOG_FATAL
    
    BitVecDeinit(&source);
    // Test BitVecFindAllPattern function
    bool test_bitvec_find_all_pattern(void) {
    WriteFmt("Testing BitVecFindAllPattern function\n");
    
    BitVec source  = BitVecInit();
    
    size results[10];
    u64  count = BitVecFindAllPattern(&source, &pattern, results, 10);
    
    // Should find pattern at indices 0, 2, 4, 6, 8
    
    // Test with limited results array
    u64 count_limited = BitVecFindAllPattern(&source, &pattern, results, 3);
    result            = result && (count_limited == 3); // Should only return first 3 matches
    BitVecPush(&pattern, false);
    
    count  = BitVecFindAllPattern(&source, &pattern, results, 10);
    result = result && (count == 3); // Should find at 0, 3, 6
    BitVecPush(&pattern, true);
    
    u64 count = BitVecFindAllPattern(&source, &pattern, results, 1);
    result    = result && (count == 1);
    result    = result && (results[0] == 0);
    // Test finding all occurrences in large data
    size results[200];
    u64  count = BitVecFindAllPattern(&source, &pattern, results, 200);
    result     = result && (count > 0); // Should find at least some patterns

Share :

Related Posts

BitVecFindLastPattern

BitVecFindLastPattern Description Find last occurrence of a bit pattern in the bitvector.

Read More

BitVecStartsWith

BitVecStartsWith Description Check if bitvector starts with the given bit pattern.

Read More

BitVecInsertPattern

BitVecInsertPattern Description Insert a bit pattern from a byte at a specific position. Only the specified number of bits from the pattern are inserted.

Read More