integrat ecrupp review suggestions

This commit is contained in:
Gregory Burd 2024-05-06 15:43:47 -04:00
parent 3b8e083806
commit 367d15a160
5 changed files with 279 additions and 275 deletions

View file

@ -68,6 +68,6 @@ include in `lib` the amalgamated (git `2dc8070`) and well-known
[Roaring Bitmaps](https://github.com/RoaringBitmap/CRoaring/tree/master) and
use it in the soak test to ensure our results are as accurate as theirs.
This library was created for [hamsterdb](http://hamsterdb.com) in
This library was originally created by [Christoph Rupp](https://crupp.de) in
C++ and then translated to C and further improved by Greg Burd <greg@burd.me>
for use in LMDB and OpenLDAP.

View file

@ -100,7 +100,7 @@ typedef uint64_t sm_bitvec_t;
*
* The buffer used for the bitmap is allocated in the same heap allocation as
* the structure, this means that you only need to call free() on the returned
* object to free all resources. Using this method it is allowable to grow the
* object to free all resources. Using this method allows you to grow the
* buffer size by calling #sparsemap_set_data_size(). This function calls
* #sparsemap_init().
*
@ -122,9 +122,9 @@ sparsemap_t *sparsemap_copy(sparsemap_t *other);
* This function allocates a new sparsemap_t but not the buffer which is
* provided by the caller as \b data which can be allocated on the stack or
* heap. Caller is responsible for calling free() on the returned heap object
* and releasing the memory used for \b data. Resizing the buffer is not
* directly supported, you may attempt to resize by calling
* #sparsemap_set_data_size() with the potentially relocated address of \b data.
* and releasing the memory used for \b data. Resizing the buffer is only
* supported when the heap object for the map includes the buffer and the
* \b data offset supplied is relative to the object (see #sparsemap()).
* This function calls #sparsemap_init().
*
* @param[in] data A heap or stack memory buffer of \b size for use storing
@ -168,7 +168,7 @@ void sparsemap_init(sparsemap_t *map, uint8_t *data, size_t size);
void sparsemap_open(sparsemap_t *map, uint8_t *data, size_t size);
/** @brief Resets values and empties the buffer making it ready to accept new
* data.
* data but does not free the memory.
*
* @param[in] map The sparsemap reference.
*/
@ -195,7 +195,7 @@ void sparsemap_clear(sparsemap_t *map);
* @note The resizing of caller supplied allocated objects is not yet fully
* supported.
*/
sparsemap_t *sparsemap_set_data_size(sparsemap_t *map, size_t size, uint8_t *data);
sparsemap_t *sparsemap_set_data_size(sparsemap_t *map, uint8_t *data, size_t size);
/** @brief Calculate remaining capacity, approaches 0 when full.
*
@ -264,8 +264,7 @@ size_t sparsemap_get_size(sparsemap_t *map);
*/
void sparsemap_scan(sparsemap_t *map, void (*scanner)(sm_idx_t vec[], size_t n, void *aux), size_t skip, void *aux);
/** @brief Merges the values from \b other into the \b map, \b other is unchanged.
* \b other bitmap while removing them from \b map.
/** @brief Merges the values from \b other into \b map, \b other is unchanged.
*
* @param[in] map The sparsemap reference.
* @param[in] other The bitmap to merge into \b map.
@ -277,7 +276,7 @@ int sparsemap_merge(sparsemap_t *map, sparsemap_t *other);
/** @brief Splits the bitmap by assigning all bits starting at \b offset to the
* \b other bitmap while removing them from \b map.
*
* The split must occur on a vector boundary.
* The \b other bitmap is expected to be empty.
*
* @param[in] map The sparsemap reference.
* @param[in] offset The 0-based offset into the bitmap at which to split.
@ -327,14 +326,14 @@ size_t sparsemap_rank(sparsemap_t *map, size_t x, size_t y, bool value);
* matching \b value in the bitmap.
*
* @param[in] map The sparsemap reference.
* @param[in] idx 0-based start of search within the bitmap.
* @param[in] start 0-based start of search within the bitmap.
* @param[in] len The length of contiguous bits we're seeking.
* @param[in] value Determines if the scan is to find all set (true) or unset
* (false) bits of \b len.
* @returns the index of the first bit matching the criteria; when not found
* found SPARSEMAP_IDX_MAX
*/
size_t sparsemap_span(sparsemap_t *map, sparsemap_idx_t idx, size_t len, bool value);
size_t sparsemap_span(sparsemap_t *map, sparsemap_idx_t start, size_t len, bool value);
#if defined(__cplusplus)
}

File diff suppressed because it is too large Load diff

View file

@ -617,7 +617,7 @@ _sparsemap_set(sparsemap_t **map, sparsemap_idx_t idx, bool value)
sparsemap_idx_t l = sparsemap_set(*map, idx, value);
if (l != idx) {
if (errno == ENOSPC) {
*map = sparsemap_set_data_size(*map, sparsemap_get_capacity(*map) + 64, NULL);
*map = sparsemap_set_data_size(*map, NULL, sparsemap_get_capacity(*map) + 64);
assert(*map != NULL);
errno = 0;
} else {
@ -637,7 +637,7 @@ _sparsemap_merge(sparsemap_t **map, sparsemap_t *other)
if (retval != 0) {
if (errno == ENOSPC) {
size_t new_size = retval + (64 - (retval % 64)) + 64;
*map = sparsemap_set_data_size(*map, sparsemap_get_capacity(*map) + new_size, NULL);
*map = sparsemap_set_data_size(*map, NULL, sparsemap_get_capacity(*map) + new_size);
assert(*map != NULL);
errno = 0;
} else {

View file

@ -102,7 +102,7 @@ test_api_new_realloc(const MunitParameter params[], void *data)
assert_true(map->m_capacity == 1024);
assert_true(map->m_data_used == sizeof(uint32_t));
map = sparsemap_set_data_size(map, 2048, NULL);
map = sparsemap_set_data_size(map, NULL, 2048);
assert_true(map->m_capacity == 2048);
assert_true(map->m_data_used == sizeof(uint32_t));
@ -275,7 +275,7 @@ test_api_set_data_size(const MunitParameter params[], void *data)
assert_ptr_not_null(map);
assert_true(map->m_capacity == 1024);
assert_true(map->m_capacity == sparsemap_get_capacity(map));
sparsemap_set_data_size(map, 512, NULL);
sparsemap_set_data_size(map, NULL, 512);
assert_true(map->m_capacity == 512);
assert_true(map->m_capacity == sparsemap_get_capacity(map));
return MUNIT_OK;
@ -1063,7 +1063,7 @@ test_scale_lots_o_spans(const MunitParameter params[], void *data)
int l = i % 31 + 16;
sm_add_span(map, 10000, l);
if (errno == ENOSPC) {
map = sparsemap_set_data_size(map, sparsemap_get_capacity(map) * 2, NULL);
map = sparsemap_set_data_size(map, NULL, sparsemap_get_capacity(map) * 2);
errno = 0;
}
i += l;
@ -1109,7 +1109,7 @@ test_scale_ondrej(const MunitParameter params[], void *data)
bool set = (i != needle) ? (j < 10) : (j < 9);
sparsemap_set(map, i, set);
if (errno == ENOSPC) {
map = sparsemap_set_data_size(map, sparsemap_get_capacity(map) * 2, NULL);
map = sparsemap_set_data_size(map, NULL, sparsemap_get_capacity(map) * 2);
errno = 0;
}
}
@ -1177,7 +1177,7 @@ test_scale_spans_come_spans_go(const MunitParameter params[], void *data)
int l = i % 31 + 16;
sm_add_span(map, amt, l);
if (errno == ENOSPC) {
map = sparsemap_set_data_size(map, sparsemap_get_capacity(map) + 1024, NULL);
map = sparsemap_set_data_size(map, NULL, sparsemap_get_capacity(map) + 1024);
assert_ptr_not_null(map);
errno = 0;
}