BitVecDotProduct
BitVecDotProduct
Description
Calculate dot product of two bitvectors. Dot product is the count of positions where both bits are 1.
Parameters
| Name | Direction | Description |
|---|---|---|
bv1 |
in | First bitvector |
bv2 |
in | Second bitvector |
Usage example (from documentation)
u64 dot_product = BitVecDotProduct(&bv1, &bv2);Returns
Number of positions where both bits are 1
Usage example (Cross-references)
Usage examples (Cross-references)
- In
BitVec.c:1191:
// Use BitVecDotProduct for intersection calculation
u64 intersection = BitVecDotProduct(bv1, bv2);
// Calculate union count
- In
BitVec.c:1213:
ValidateBitVec(bv2);
u64 dot_product = BitVecDotProduct(bv1, bv2);
u64 ones1 = BitVecCountOnes(bv1);
u64 ones2 = BitVecCountOnes(bv2);- In
BitVec.c:1227:
}
u64 BitVecDotProduct(BitVec *bv1, BitVec *bv2) {
ValidateBitVec(bv1);
ValidateBitVec(bv2); // Test BitVecDotProduct basic functionality
bool test_bitvec_dot_product_basic(void) {
WriteFmt("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) {
WriteFmt("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) {
WriteFmt("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) {
WriteFmt("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;
Last updated on