BitVecStartsWith

Table of Contents

BitVecStartsWith

Description

Check if bitvector starts with the given bit pattern.

Parameters

NameDirectionDescription
bvinBitvector to check
prefixinPattern to match at the beginning

Usage example (from documentation)

  bool starts = BitVecStartsWith(&flags, &pattern);

Usage example (Cross-references)

    // Missing Pattern functions implementation
    
    bool BitVecStartsWith(BitVec *bv, BitVec *prefix) {
    ValidateBitVec(bv);
    ValidateBitVec(prefix);
    
    VecForeachPtrIdx(patterns, pattern, i, {
    if (BitVecStartsWith(bv, pattern)) {
    return i;
    }
    
    bool test_bitvec_starts_with_null_source(void) {
    printf("Testing BitVecStartsWith(NULL, prefix) - should fatal\n");
    BitVec prefix = BitVecInit();
    BitVecPush(&prefix, true);
    BitVec prefix = BitVecInit();
    BitVecPush(&prefix, true);
    BitVecStartsWith(NULL, &prefix);
    BitVecDeinit(&prefix);
    return true;
    
    bool test_bitvec_starts_with_null_prefix(void) {
    printf("Testing BitVecStartsWith(source, NULL) - should fatal\n");
    BitVec source = BitVecInit();
    BitVecPush(&source, true);
    BitVec source = BitVecInit();
    BitVecPush(&source, true);
    BitVecStartsWith(&source, NULL);
    BitVecDeinit(&source);
    return true;
    // BitVecStartsWith tests
    bool test_bitvec_starts_with_basic(void) {
    printf("Testing BitVecStartsWith basic functionality\n");
    
    BitVec source = BitVecInit();
    BitVecPush(&prefix, false);
    
    result = result && BitVecStartsWith(&source, &prefix);
    
    // Test non-matching prefix: 101
    BitVecPush(&prefix, true);
    
    result = result && !BitVecStartsWith(&source, &prefix);
    
    BitVecDeinit(&source);
    
    bool test_bitvec_starts_with_edge_cases(void) {
    printf("Testing BitVecStartsWith edge cases\n");
    
    BitVec source = BitVecInit();
    // Test empty prefix (should always match)
    BitVecPush(&source, true);
    result = result && BitVecStartsWith(&source, &prefix);
    
    // Test prefix longer than source
    BitVecPush(&prefix, true);
    BitVecPush(&prefix, false);
    result = result && !BitVecStartsWith(&source, &prefix);
    
    // Test equal length
    BitVecPush(&prefix, true);
    BitVecPush(&prefix, false);
    result = result && BitVecStartsWith(&source, &prefix);
    
    BitVecDeinit(&source);
    // BitVecStartsWith tests
    bool test_bitvec_starts_with_basic(void) {
    printf("Testing BitVecStartsWith basic functionality\n");
    
    BitVec source = BitVecInit();
    BitVecPush(&prefix, false);
    
    result = result && BitVecStartsWith(&source, &prefix);
    
    // Test non-matching prefix: 101
    BitVecPush(&prefix, true);
    
    result = result && !BitVecStartsWith(&source, &prefix);
    
    BitVecDeinit(&source);
    
    bool test_bitvec_starts_with_edge_cases(void) {
    printf("Testing BitVecStartsWith edge cases\n");
    
    BitVec source = BitVecInit();
    // Test empty prefix (should always match)
    BitVecPush(&source, true);
    result = result && BitVecStartsWith(&source, &prefix);
    
    // Test prefix longer than source
    BitVecPush(&prefix, true);
    BitVecPush(&prefix, false);
    result = result && !BitVecStartsWith(&source, &prefix);
    
    // Test equal length
    BitVecPush(&prefix, true);
    BitVecPush(&prefix, false);
    result = result && BitVecStartsWith(&source, &prefix);
    
    BitVecDeinit(&source);
    
    bool test_bitvec_starts_with_null_source(void) {
    printf("Testing BitVecStartsWith(NULL, prefix) - should fatal\n");
    BitVec prefix = BitVecInit();
    BitVecPush(&prefix, true);
    BitVec prefix = BitVecInit();
    BitVecPush(&prefix, true);
    BitVecStartsWith(NULL, &prefix);
    BitVecDeinit(&prefix);
    return true;
    
    bool test_bitvec_starts_with_null_prefix(void) {
    printf("Testing BitVecStartsWith(source, NULL) - should fatal\n");
    BitVec source = BitVecInit();
    BitVecPush(&source, true);
    BitVec source = BitVecInit();
    BitVecPush(&source, true);
    BitVecStartsWith(&source, NULL);
    BitVecDeinit(&source);
    return true;

Share :

Related Posts

BitVecToStr

BitVecToStr Description Convert bitvector to string representation. Each bit becomes ‘1’ or ‘0’ character. Caller must free the returned string.

Read More

BitVecToBytes

BitVecToBytes Description Export bitvector to byte array. Copies the internal bit representation to the provided byte array.

Read More

BitVecFromStr

BitVecFromStr Description Create bitvector from string representation. String should contain only ‘1’ and ‘0’ characters.

Read More