diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d28802..59eee56 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ set(SOURCE_DIR .) set(HEADER_DIR . test) set(COMMON_CMAKE_C_FLAGS "-std=c11 -Wall -Wextra -Wpedantic") -set(CMAKE_C_FLAGS_DEBUG "-DSPARSEMAP_DIAGNOSTIC -DSPARSEMAP_TESTING -DDEBUG -g -O0") +set(CMAKE_C_FLAGS_DEBUG "-DSPARSEMAP_DIAGNOSTIC -DSPARSEMAP_TESTING -DDEBUG -g -Og") set(CMAKE_C_FLAGS_PROFILE "-DSPARSEMAP_DIAGNOSTIC -DSPARSEMAP_TESTING -DDEBUG -g -Og -fsanitize=address,leak,object-size,pointer-compare,pointer-subtract,null,return,bounds,pointer-overflow,undefined -fsanitize-address-use-after-scope") set(CMAKE_C_FLAGS_RELEASE "-Ofast") diff --git a/sparsemap.c b/sparsemap.c index 67582f9..3ed1c70 100644 --- a/sparsemap.c +++ b/sparsemap.c @@ -1090,8 +1090,18 @@ __sm_get_chunk_data(sparsemap_t *map, size_t offset) return &map->m_data[SM_SIZEOF_OVERHEAD + offset]; } -/** @brief - * TODO only call this with an offset of an RLE chunk +/** @brief Either max capacity or limited by next chunk. + * + * Use this function to determine the available room (capacity) in bits between + * the end of an RLE chunk and the beginning of the next chunk (if one exists). + * This function will assume that \b offset is the location of an RLE chunk and + * then using that probe for the start of the next chunk. + * + * @param[in] map The map containing the RLE chunk. + * @param[in] start The starting index of the RLE chunk. + * @param[in] offset The offset in m_data of the RLE chunk. + * @return a value between [0, SM_CHUNK_RLE_MAX_CAPACITY] based on the + * position/existence of the next chunk in the map. */ static size_t __sm_chunk_rle_capacity_limit(sparsemap_t *map, __sm_idx_t start, size_t offset) @@ -1931,7 +1941,9 @@ sparsemap_unset(sparsemap_t *map, sparsemap_idx_t idx) } done:; - __sm_coalesce_chunk(map, &chunk, offset, start, p); + if (offset != SPARSEMAP_IDX_MAX) { + __sm_coalesce_chunk(map, &chunk, offset, start, p); + } //__sm_when_diag({ fprintf(stdout, "\n++++++++++++++++++++++++++++++ unset: %lu\n%s\n", idx, QCC_showSparsemap(map, 0)); }); return ret_idx; }