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);Success
true if bits are in non-decreasing order (0s before 1s)
Failure
false when any 0-bit follows a 1-bit in bv.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
BitVec.c:869:
}
bool BitVecIsSorted(const BitVec *bv) {
ValidateBitVec(bv);- In
Compare.c:632:
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecIsSorted\n");
BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));- In
Compare.c:637:
// Test empty bitvector (should be sorted)
bool result = BitVecIsSorted(&bv);
// Test sorted pattern: 0001111
- In
Compare.c:648:
BitVecPush(&bv, true);
result = result && BitVecIsSorted(&bv);
// Test unsorted pattern (add 0 after 1s)
- In
Compare.c:652:
// Test unsorted pattern (add 0 after 1s)
BitVecPush(&bv, false);
result = result && !BitVecIsSorted(&bv);
// Test all zeros
- In
Compare.c:659:
BitVecPush(&bv, false);
}
result = result && BitVecIsSorted(&bv);
// Test all ones
- In
Compare.c:666:
BitVecPush(&bv, true);
}
result = result && BitVecIsSorted(&bv);
// Clean up
- In
Compare.c:959:
// Test NULL pointer - should abort
BitVecIsSorted(NULL);
return false;
Last updated on