use chunk alignment; new fill factor API

This commit is contained in:
Gregory Burd 2024-05-15 15:50:15 -04:00
parent b028408150
commit 69dd960558
2 changed files with 16 additions and 1 deletions

View file

@ -285,6 +285,13 @@ sparsemap_idx_t sparsemap_get_starting_offset(sparsemap_t *map);
*/
sparsemap_idx_t sparsemap_get_ending_offset(sparsemap_t *map);
/** @brief Returns the percent of bits set in the map.
*
* @param[in] map The sparsemap reference.
* @returns the percent of bits set.
*/
double sparsemap_fill_factor(sparsemap_t *map);
/** @brief Provides a method for a callback function to examine every bit set in
* the index.
*

View file

@ -1183,7 +1183,7 @@ sparsemap_set(sparsemap_t *map, sparsemap_idx_t idx, bool value)
__sm_append_data(map, &buf[0], sizeof(buf));
uint8_t *p = __sm_get_chunk_data(map, 0);
*(sm_idx_t *)p = __sm_get_vector_aligned_offset(idx); // TODO: vector or chunk aligned?
*(sm_idx_t *)p = __sm_get_chunk_aligned_offset(idx); // TODO: vector or chunk aligned?
__sm_set_chunk_count(map, 1);
@ -1384,6 +1384,14 @@ sparsemap_get_ending_offset(sparsemap_t *map)
return offset;
}
double
sparsemap_fill_factor(sparsemap_t *map)
{
size_t rank = sparsemap_rank(map, 0, SPARSEMAP_IDX_MAX, true);
sparsemap_idx_t end = sparsemap_get_ending_offset(map);
return (double)rank / (double)end * 100.0;
}
void *
sparsemap_get_data(sparsemap_t *map)
{