BitVecRunLengths
- Function
- August 22, 2025
Table of Contents
BitVecRunLengths
BitVecRunLengths
Description
Analyze run lengths in a bitvector. A run is a sequence of consecutive identical bits. Results array must be pre-allocated with sufficient space.
Parameters
Name | Direction | Description |
---|---|---|
bv | in | Bitvector to analyze |
runs | out | Array to store run lengths |
values | out | Array to store run values (true/false) |
max_runs | in | Maximum number of runs to store |
Usage example (from documentation)
u64 run_lengths[50];
bool run_values[50];
u64 count = BitVecRunLengths(&flags, run_lengths, run_values, 50);
Usage example (Cross-references)
- In
BitVec.c:1114
:
// Foreach functions
u64 BitVecRunLengths(BitVec *bv, u64 *runs, bool *values, u64 max_runs) {
ValidateBitVec(bv);
if (!runs || !values || max_runs == 0) {
bool test_bitvec_run_lengths_basic(void) {
printf("Testing BitVecRunLengths basic functionality\n");
BitVec bv = BitVecInit();
u64 runs[10];
bool values[10];
u64 count = BitVecRunLengths(&bv, runs, values, 10);
// Should find 5 runs
bool test_bitvec_run_lengths_edge_cases(void) {
printf("Testing BitVecRunLengths edge cases\n");
bool result = true;
u64 runs[5];
bool values[5];
u64 count = BitVecRunLengths(&empty_bv, runs, values, 5);
result = result && (count == 0);
BitVecDeinit(&empty_bv);
BitVec single_bv = BitVecInit();
BitVecPush(&single_bv, true);
count = BitVecRunLengths(&single_bv, runs, values, 5);
result = result && (count == 1);
result = result && (runs[0] == 1 && values[0] == true);
BitVec single_false_bv = BitVecInit();
BitVecPush(&single_false_bv, false);
count = BitVecRunLengths(&single_false_bv, runs, values, 5);
result = result && (count == 1);
result = result && (runs[0] == 1 && values[0] == false);
BitVecPush(&all_true_bv, true);
}
count = BitVecRunLengths(&all_true_bv, runs, values, 5);
result = result && (count == 1);
result = result && (runs[0] == 10 && values[0] == true);
u64 alt_runs[10];
bool alt_values[10];
count = BitVecRunLengths(&alternating_bv, alt_runs, alt_values, 10);
result = result && (count == 7); // Each bit is its own run
// Verify alternating pattern
bool test_bitvec_run_lengths_boundary_conditions(void) {
printf("Testing BitVecRunLengths boundary conditions\n");
BitVec bv = BitVecInit();
u64 runs[3];
bool values[3];
u64 count = BitVecRunLengths(&bv, runs, values, 3);
// Should only capture first 3 runs due to limit
// Test with max_runs = 1
count = BitVecRunLengths(&bv, runs, values, 1);
result = result && (count == 1);
result = result && (runs[0] == 1 && values[0] == true);
u64 large_runs[8];
bool large_values[8];
count = BitVecRunLengths(&bv, large_runs, large_values, 8);
result = result && (count == 8);
bool test_bitvec_run_lengths_stress_test(void) {
printf("Testing BitVecRunLengths stress test\n");
bool result = true;
u64 runs[200];
bool values[200];
u64 count = BitVecRunLengths(&large_bv, runs, values, 200);
// Should have 100 runs (100 blocks)
u64 small_runs[10];
bool small_values[10];
count = BitVecRunLengths(&large_bv, small_runs, small_values, 10);
// Expected runs: [4T, 4F, 3T, 3F, 1T, 4F, 3T] = 7 runs
bool test_bitvec_run_lengths_null_bv(void) {
printf("Testing BitVecRunLengths with NULL bitvector\n");
u64 runs[5];
// This should cause LOG_FATAL and terminate the program
BitVecRunLengths(NULL, runs, values, 5);
return true; // Should never reach here
bool test_bitvec_run_lengths_null_runs(void) {
printf("Testing BitVecRunLengths with NULL runs array\n");
BitVec bv = BitVecInit();
// This should cause LOG_FATAL and terminate the program
BitVecRunLengths(&bv, NULL, values, 5);
BitVecDeinit(&bv);
bool test_bitvec_run_lengths_null_values(void) {
printf("Testing BitVecRunLengths with NULL values array\n");
BitVec bv = BitVecInit();
// This should cause LOG_FATAL and terminate the program
BitVecRunLengths(&bv, runs, NULL, 5);
BitVecDeinit(&bv);
bool test_bitvec_run_lengths_zero_max_runs(void) {
printf("Testing BitVecRunLengths with zero max_runs\n");
BitVec bv = BitVecInit();
// This should cause LOG_FATAL and terminate the program
BitVecRunLengths(&bv, runs, values, 0);
BitVecDeinit(&bv);
bool test_bitvec_run_lengths_basic(void) {
printf("Testing BitVecRunLengths basic functionality\n");
BitVec bv = BitVecInit();
u64 runs[10];
bool values[10];
u64 count = BitVecRunLengths(&bv, runs, values, 10);
// Should find 5 runs
bool test_bitvec_run_lengths_edge_cases(void) {
printf("Testing BitVecRunLengths edge cases\n");
bool result = true;
u64 runs[5];
bool values[5];
u64 count = BitVecRunLengths(&empty_bv, runs, values, 5);
result = result && (count == 0);
BitVecDeinit(&empty_bv);
BitVec single_bv = BitVecInit();
BitVecPush(&single_bv, true);
count = BitVecRunLengths(&single_bv, runs, values, 5);
result = result && (count == 1);
result = result && (runs[0] == 1 && values[0] == true);
BitVec single_false_bv = BitVecInit();
BitVecPush(&single_false_bv, false);
count = BitVecRunLengths(&single_false_bv, runs, values, 5);
result = result && (count == 1);
result = result && (runs[0] == 1 && values[0] == false);
BitVecPush(&all_true_bv, true);
}
count = BitVecRunLengths(&all_true_bv, runs, values, 5);
result = result && (count == 1);
result = result && (runs[0] == 10 && values[0] == true);
u64 alt_runs[10];
bool alt_values[10];
count = BitVecRunLengths(&alternating_bv, alt_runs, alt_values, 10);
result = result && (count == 7); // Each bit is its own run
// Verify alternating pattern
bool test_bitvec_run_lengths_boundary_conditions(void) {
printf("Testing BitVecRunLengths boundary conditions\n");
BitVec bv = BitVecInit();
u64 runs[3];
bool values[3];
u64 count = BitVecRunLengths(&bv, runs, values, 3);
// Should only capture first 3 runs due to limit
// Test with max_runs = 1
count = BitVecRunLengths(&bv, runs, values, 1);
result = result && (count == 1);
result = result && (runs[0] == 1 && values[0] == true);
u64 large_runs[8];
bool large_values[8];
count = BitVecRunLengths(&bv, large_runs, large_values, 8);
result = result && (count == 8);
bool test_bitvec_run_lengths_stress_test(void) {
printf("Testing BitVecRunLengths stress test\n");
bool result = true;
u64 runs[200];
bool values[200];
u64 count = BitVecRunLengths(&large_bv, runs, values, 200);
// Should have 100 runs (100 blocks)
u64 small_runs[10];
bool small_values[10];
count = BitVecRunLengths(&large_bv, small_runs, small_values, 10);
// Expected runs: [4T, 4F, 3T, 3F, 1T, 4F, 3T] = 7 runs
bool test_bitvec_run_lengths_null_bv(void) {
printf("Testing BitVecRunLengths with NULL bitvector\n");
u64 runs[5];
// This should cause LOG_FATAL and terminate the program
BitVecRunLengths(NULL, runs, values, 5);
return true; // Should never reach here
bool test_bitvec_run_lengths_null_runs(void) {
printf("Testing BitVecRunLengths with NULL runs array\n");
BitVec bv = BitVecInit();
// This should cause LOG_FATAL and terminate the program
BitVecRunLengths(&bv, NULL, values, 5);
BitVecDeinit(&bv);
bool test_bitvec_run_lengths_null_values(void) {
printf("Testing BitVecRunLengths with NULL values array\n");
BitVec bv = BitVecInit();
// This should cause LOG_FATAL and terminate the program
BitVecRunLengths(&bv, runs, NULL, 5);
BitVecDeinit(&bv);
bool test_bitvec_run_lengths_zero_max_runs(void) {
printf("Testing BitVecRunLengths with zero max_runs\n");
BitVec bv = BitVecInit();
// This should cause LOG_FATAL and terminate the program
BitVecRunLengths(&bv, runs, values, 0);
BitVecDeinit(&bv);