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);
    // Deadend test 5: BitVecFindAllPattern with NULL source
    bool test_bitvec_find_all_pattern_null_source(void) {
    printf("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) {
    printf("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) {
    printf("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) {
    printf("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) {
    printf("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
    // Test BitVecFindAllPattern function
    bool test_bitvec_find_all_pattern(void) {
    printf("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) {
    printf("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) {
    printf("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) {
    printf("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) {
    printf("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);

Share :

Related Posts

BitVecToInteger

BitVecToInteger Description Convert bitvector to integer (up to 64 bits). Treats the bitvector as an unsigned integer with LSB first.

Read More

BitVecFromBytes

BitVecFromBytes Description Create bitvector from byte array. Reads the specified number of bits from the byte array.

Read More

BitVecFromInteger

BitVecFromInteger Description Create bitvector from integer value. Creates a bitvector representing the specified number of bits from the integer.

Read More