BitVecCompare
Description
Compare two bitvectors lexicographically. Comparison is done bit by bit from left to right.
Parameters
| Name | Direction | Description |
|---|---|---|
bv1 |
in | First bitvector |
bv2 |
in | Second bitvector |
Usage example (from documentation)
int result = BitVecCompare(&flags1, &flags2);Success
-1 if bv1 < bv2, 0 if equal, 1 if bv1 > bv2
Failure
Cannot fail; aborts on a corrupted magic via the validator.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
BitVec.c:707:
i32 bitvec_compare(const void *lhs, const void *rhs) {
return (i32)BitVecCompare((const BitVec *)lhs, (const BitVec *)rhs);
}- In
BitVec.c:710:
}
int BitVecCompare(const BitVec *bv1, const BitVec *bv2) {
ValidateBitVec(bv1);
ValidateBitVec(bv2);- In
Compare.c:99:
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecCompare\n");
BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));- In
Compare.c:111:
BitVecPush(&bv2, false);
bool result = (BitVecCompare(&bv1, &bv2) == 0);
// Test first greater than second
- In
Compare.c:123:
BitVecPush(&bv2, false); // 10
result = result && (BitVecCompare(&bv1, &bv2) > 0);
result = result && (BitVecCompare(&bv2, &bv1) < 0);- In
Compare.c:124:
result = result && (BitVecCompare(&bv1, &bv2) > 0);
result = result && (BitVecCompare(&bv2, &bv1) < 0);
// Clean up
- In
Compare.c:153:
// Lexicographic comparison considers position-by-position
int cmp_result = BitVecCompare(&bv1, &bv2);
bool result = (cmp_result != 0); // Should not be equal
- In
Compare.c:162:
BitVecPush(&bv2, true); // 101
result = result && (BitVecCompare(&bv1, &bv2) == 0);
// Clean up
- In
Compare.c:604:
// Lexicographically, shorter comes first
bool result = (BitVecCompare(&bv1, &bv2) < 0);
// Numerically, 10 (2) < 101 (5)
- In
Compare.c:611:
// Test equal cases
BitVec bv3 = BitVecClone(&bv1);
result = result && !(BitVecCompare(&bv1, &bv3) < 0);
result = result && !(BitVecNumericalCompare(&bv1, &bv3) < 0);- In
Compare.c:615:
// Test reverse comparison
result = result && !(BitVecCompare(&bv2, &bv1) < 0);
result = result && !(BitVecNumericalCompare(&bv2, &bv1) < 0);- In
Compare.c:688:
// Test compare empty bitvecs
result = result && BitVecEquals(&bv1, &bv2);
result = result && (BitVecCompare(&bv1, &bv2) == 0);
// Test compare empty vs non-empty
- In
Compare.c:693:
BitVecPush(&bv1, true);
result = result && !BitVecEquals(&bv1, &bv2);
result = result && (BitVecCompare(&bv1, &bv2) != 0);
// Test large identical bitvecs
- In
Compare.c:776:
// Numerical: 86 < 89, so bv1 < bv2
result = result && (BitVecNumericalCompare(&bv1, &bv2) < 0);
result = result && (BitVecCompare(&bv1, &bv2) < 0);
// Weight: bv1 has 4 ones, bv2 has 4 ones, so equal weight
- In
Compare.c:782:
// Lexicographic comparison
int lex_cmp = BitVecCompare(&bv1, &bv2);
bool lex_less = (BitVecCompare(&bv1, &bv2) < 0);
result = result && ((lex_cmp < 0) == lex_less);- In
Compare.c:783:
// Lexicographic comparison
int lex_cmp = BitVecCompare(&bv1, &bv2);
bool lex_less = (BitVecCompare(&bv1, &bv2) < 0);
result = result && ((lex_cmp < 0) == lex_less);- In
Compare.c:1246:
BitVecPush(&bv, true);
BitVecCompare(NULL, &bv); // must abort
BitVecDeinit(&bv);- In
Compare.c:1261:
BitVecPush(&bv, true);
BitVecCompare(&bv, NULL); // must abort
BitVecDeinit(&bv);
Last updated on