2024-04-05 14:34:59 +00:00
|
|
|
#include <assert.h>
|
2024-04-24 20:32:09 +00:00
|
|
|
#include <stdbool.h>
|
2024-04-05 14:34:59 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "../include/sparsemap.h"
|
|
|
|
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wvariadic-macros"
|
|
|
|
#define __diag(...) \
|
|
|
|
do { \
|
|
|
|
fprintf(stderr, "%s:%d:%s(): ", __FILE__, __LINE__, __func__); \
|
|
|
|
fprintf(stderr, __VA_ARGS__); \
|
|
|
|
} while (0)
|
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
2024-04-24 20:32:09 +00:00
|
|
|
int i;
|
2024-04-05 14:34:59 +00:00
|
|
|
|
|
|
|
// disable buffering
|
2024-04-24 20:32:09 +00:00
|
|
|
setvbuf(stdout, NULL, _IONBF, 0); // Disable buffering for stdout
|
|
|
|
setvbuf(stderr, NULL, _IONBF, 0); // Disable buffering for stdout
|
2024-04-05 14:34:59 +00:00
|
|
|
|
|
|
|
// start with a 1KiB buffer, 1024 bits
|
|
|
|
uint8_t *buf = calloc(1024, sizeof(uint8_t));
|
|
|
|
|
|
|
|
// create the sparse bitmap
|
2024-04-24 20:32:09 +00:00
|
|
|
sparsemap_t *map = sparsemap_wrap(buf, sizeof(uint8_t) * 1024);
|
2024-04-05 14:34:59 +00:00
|
|
|
|
|
|
|
// Set every other bit (pathologically worst case) to see what happens
|
|
|
|
// when the map is full.
|
|
|
|
for (i = 0; i < 7744; i++) {
|
2024-04-24 20:32:09 +00:00
|
|
|
if (!i % 2) {
|
|
|
|
sparsemap_set(map, i, true);
|
|
|
|
assert(sparsemap_is_set(map, i) == true);
|
|
|
|
}
|
2024-04-05 14:34:59 +00:00
|
|
|
}
|
|
|
|
// On 1024 KiB of buffer with every other bit set the map holds 7744 bits
|
|
|
|
// and then runs out of space. This next _set() call will fail/abort.
|
|
|
|
sparsemap_set(map, ++i, true);
|
|
|
|
assert(sparsemap_is_set(map, i) == true);
|
|
|
|
return 0;
|
|
|
|
}
|