BitVecBestAlignment
Description
Find best overlapping alignment between two bitvectors. Returns the offset that gives the best alignment score.
Parameters
| Name | Direction | Description |
|---|---|---|
bv1 |
in | First bitvector (reference) |
bv2 |
in | Second bitvector (query) |
Usage example (from documentation)
u64 offset = BitVecBestAlignment(&reference, &query);Success
Returns the offset in bv1 at which bv2 produces the highest alignment score. Neither operand is modified.
Failure
Returns SIZE_MAX when either operand is empty or no candidate alignment yields a positive score. The bitvectors are not modified.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
BitVec.c:1627:
}
u64 BitVecBestAlignment(BitVec *bv1, BitVec *bv2) {
ValidateBitVec(bv1);
ValidateBitVec(bv2); DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecBestAlignment basic functionality\n");
BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc)); BitVecPush(&bv2, false);
u64 best_pos = BitVecBestAlignment(&bv1, &bv2);
result = result && (best_pos == 0 || best_pos == 4); DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecBestAlignment edge cases\n");
BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
// Test empty bitvectors
u64 best_pos = BitVecBestAlignment(&bv1, &bv2);
result = result && (best_pos == 0); BitVecPush(&bv2, false);
best_pos = BitVecBestAlignment(&bv1, &bv2);
result = result && (best_pos == 0); double entropy1 = BitVecEntropy(&bv1);
int align_score = BitVecAlignmentScore(&bv1, &bv2, 1, -1);
u64 best_align = BitVecBestAlignment(&bv1, &bv2);
// Test edit distance with smaller vectors (expensive operation)
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecBestAlignment(NULL, bv2) - should fatal\n");
BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
BitVecPush(&bv2, true); BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
BitVecPush(&bv2, true);
BitVecBestAlignment(NULL, &bv2);
BitVecDeinit(&bv2);
DefaultAllocatorDeinit(&alloc); DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecBestAlignment(bv1, NULL) - should fatal\n");
BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
BitVecPush(&bv1, true); BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
BitVecPush(&bv1, true);
BitVecBestAlignment(&bv1, NULL);
BitVecDeinit(&bv1);
DefaultAllocatorDeinit(&alloc);
Last updated on