BitVecDotProduct

Table of Contents

BitVecDotProduct

Description

Calculate dot product of two bitvectors. Dot product is the count of positions where both bits are 1.

Parameters

NameDirectionDescription
bv1inFirst bitvector
bv2inSecond bitvector

Usage example (from documentation)

  u64 dot_product = BitVecDotProduct(&bv1, &bv2);

Usage example (Cross-references)

    
    // Use BitVecDotProduct for intersection calculation
    u64 intersection = BitVecDotProduct(bv1, bv2);
    
    // Calculate union count
    ValidateBitVec(bv2);
    
    u64 dot_product = BitVecDotProduct(bv1, bv2);
    u64 ones1       = BitVecCountOnes(bv1);
    u64 ones2       = BitVecCountOnes(bv2);
    }
    
    u64 BitVecDotProduct(BitVec *bv1, BitVec *bv2) {
    ValidateBitVec(bv1);
    ValidateBitVec(bv2);
    // Test BitVecDotProduct basic functionality
    bool test_bitvec_dot_product_basic(void) {
    printf("Testing BitVecDotProduct basic functionality\n");
    
    BitVec bv1    = BitVecInit();
    BitVecPush(&bv2, true);
    
    u64 product = BitVecDotProduct(&bv1, &bv2);
    result      = result && (product == 2); // Positions 0 and 3
    BitVecPush(&bv2, true);
    
    product = BitVecDotProduct(&bv1, &bv2);
    result  = result && (product == 0);
    // Test BitVecDotProduct edge cases
    bool test_bitvec_dot_product_edge_cases(void) {
    printf("Testing BitVecDotProduct edge cases\n");
    
    BitVec bv1    = BitVecInit();
    
    // Test empty bitvectors
    u64 product = BitVecDotProduct(&bv1, &bv2);
    result      = result && (product == 0);
    BitVecPush(&bv2, false);
    
    product = BitVecDotProduct(&bv1, &bv2);
    result  = result && (product == 1); // Only first position counts
    double jaccard     = BitVecJaccardSimilarity(&bv1, &bv2);
    double cosine      = BitVecCosineSimilarity(&bv1, &bv2);
    u64    dot_prod    = BitVecDotProduct(&bv1, &bv2);
    double correlation = BitVecCorrelation(&bv1, &bv2);
    double entropy1    = BitVecEntropy(&bv1);
    
    bool test_bitvec_dot_product_null_bv1(void) {
    printf("Testing BitVecDotProduct(NULL, bv2) - should fatal\n");
    BitVec bv2 = BitVecInit();
    BitVecPush(&bv2, true);
    BitVec bv2 = BitVecInit();
    BitVecPush(&bv2, true);
    BitVecDotProduct(NULL, &bv2);
    BitVecDeinit(&bv2);
    return true;
    
    bool test_bitvec_dot_product_null_bv2(void) {
    printf("Testing BitVecDotProduct(bv1, NULL) - should fatal\n");
    BitVec bv1 = BitVecInit();
    BitVecPush(&bv1, true);
    BitVec bv1 = BitVecInit();
    BitVecPush(&bv1, true);
    BitVecDotProduct(&bv1, NULL);
    BitVecDeinit(&bv1);
    return true;

Share :

Related Posts

BitVecCosineSimilarity

BitVecCosineSimilarity Description Calculate cosine similarity between two bitvectors. Treats bitvectors as binary vectors and computes cosine of angle between them.

Read More

BitVecRemoveAll

BitVecRemoveAll Description Remove all occurrences of a specific bit value. Returns the number of bits that were removed.

Read More

BitVecPop

BitVecPop Description Pop the last bit from bitvector. Returns the value of the removed bit.

Read More