BitVecIsSorted
- Function
- August 22, 2025
Table of Contents
BitVecIsSorted
BitVecIsSorted
Description
Check if bits in bitvector are in sorted order. Useful for certain algorithms and data structures.
Parameters
Name | Direction | Description |
---|---|---|
bv | in | Bitvector to check |
Usage example (from documentation)
bool sorted = BitVecIsSorted(&flags);
Usage example (Cross-references)
- In
BitVec.c:703
:
bool BitVecIsSorted(BitVec *bv) {
ValidateBitVec(bv);
// Test BitVecIsSorted function
bool test_bitvec_is_sorted(void) {
printf("Testing BitVecIsSorted\n");
BitVec bv = BitVecInit();
// Test empty bitvector (should be sorted)
bool result = BitVecIsSorted(&bv);
// Test sorted pattern: 0001111
BitVecPush(&bv, true);
result = result && BitVecIsSorted(&bv);
// Test unsorted pattern (add 0 after 1s)
// Test unsorted pattern (add 0 after 1s)
BitVecPush(&bv, false);
result = result && !BitVecIsSorted(&bv);
// Test all zeros
BitVecPush(&bv, false);
}
result = result && BitVecIsSorted(&bv);
// Test all ones
BitVecPush(&bv, true);
}
result = result && BitVecIsSorted(&bv);
// Clean up
// Test NULL pointer - should abort
BitVecIsSorted(NULL);
return false;