shrink the buffer as chunks empty #12

Merged
greg merged 2 commits from gburd/dyn-size into main 2024-07-02 13:07:25 +00:00
2 changed files with 70 additions and 6 deletions
Showing only changes of commit 63b83df5dc - Show all commits

View file

@ -33,7 +33,7 @@ option(BUILD_SHARED_LIBS "Build shared libraries" ON)
# Add shared library
add_library(sparsemap_SHARED SHARED ${LIB_SRC} ${HEADERS})
# Set target properties for shared library (adjust if needed)
# Set target properties for the shared library (adjust if needed)
set_target_properties(sparsemap_SHARED PROPERTIES
VERSION 1.0.0 # Set library version
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" # Set output directory
@ -87,8 +87,8 @@ target_link_libraries(soak PUBLIC m)
add_custom_target(run_soak COMMAND soak WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
# Add fuzzer program
add_executable(fuzzer tests/fuzzer.c)
target_link_libraries(fuzzer PRIVATE sparsemap)
target_include_directories(fuzzer PRIVATE ${HEADER_DIR} lib)
target_link_libraries(fuzzer PUBLIC m)
add_custom_target(run_fuzzer COMMAND fuzzer WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
# add_executable(fuzzer tests/fuzzer.c)
# target_link_libraries(fuzzer PRIVATE sparsemap)
# target_include_directories(fuzzer PRIVATE ${HEADER_DIR} lib)
# target_link_libraries(fuzzer PUBLIC m)
# add_custom_target(run_fuzzer COMMAND fuzzer WORKING_DIRECTORY ${CMAKE_BINARY_DIR})

View file

@ -1348,6 +1348,68 @@ test_scale_fuzz(const MunitParameter params[], void *data)
return MUNIT_OK;
}
static void *
test_scale_alternating_setup(const MunitParameter params[], void *user_data)
{
(void)params;
(void)user_data;
sparsemap_t *map = sparsemap(10 * 1024);
assert_ptr_not_null(map);
return (void *)map;
}
static void
test_scale_alternating_tear_down(void *fixture)
{
sparsemap_t *map = (sparsemap_t *)fixture;
assert_ptr_not_null(map);
munit_free(map);
}
static MunitResult
test_scale_alternating(const MunitParameter params[], void *data)
{
sparsemap_t *map = (sparsemap_t *)data;
(void)params;
for (int i = 0; i < 8192; i++) {
if (i % 2)
sparsemap_set(map, i, true);
}
return MUNIT_OK;
}
static void *
test_scale_8192_setup(const MunitParameter params[], void *user_data)
{
(void)params;
(void)user_data;
sparsemap_t *map = sparsemap(10 * 1024);
assert_ptr_not_null(map);
return (void *)map;
}
static void
test_scale_8192_tear_down(void *fixture)
{
sparsemap_t *map = (sparsemap_t *)fixture;
assert_ptr_not_null(map);
munit_free(map);
}
static MunitResult
test_scale_8192(const MunitParameter params[], void *data)
{
sparsemap_t *map = (sparsemap_t *)data;
(void)params;
for (int i = 0; i < 16384; i++) {
sparsemap_set(map, i, true);
if (i > 2049) {
sparsemap_set(map, i - 2049, false);
}
//assert_true(sparsemap_get_starting_offset(map) == (i / 2048) * 2048);
if (i % 2048 == 0) printf("%d\t%d\t%d\t%zu\n", i, i / 2048, i % 2048, sparsemap_get_starting_offset(map));
}
return MUNIT_OK;
}
static void *
test_scale_spans_come_spans_go_setup(const MunitParameter params[], void *user_data)
{
@ -1595,6 +1657,8 @@ static MunitTest scale_test_suite[] = {
{ (char *)"/ondrej", test_scale_ondrej, test_scale_ondrej_setup, test_scale_ondrej_tear_down, MUNIT_TEST_OPTION_NONE, NULL },
#endif
{ (char *)"/fuzz", test_scale_fuzz, test_scale_fuzz_setup, test_scale_fuzz_tear_down, MUNIT_TEST_OPTION_NONE, NULL },
{ (char *)"/alternating", test_scale_alternating, test_scale_alternating_setup, test_scale_alternating_tear_down, MUNIT_TEST_OPTION_NONE, NULL },
{ (char *)"/8192", test_scale_8192, test_scale_8192_setup, test_scale_8192_tear_down, MUNIT_TEST_OPTION_NONE, NULL },
{ (char *)"/spans_come_spans_go", test_scale_spans_come_spans_go, test_scale_spans_come_spans_go_setup, test_scale_spans_come_spans_go_tear_down, MUNIT_TEST_OPTION_NONE, NULL },
{ (char *)"/best-case", test_scale_best_case, test_scale_best_case_setup, test_scale_best_case_tear_down, MUNIT_TEST_OPTION_NONE, NULL },
{ (char *)"/worst-case", test_scale_worst_case, test_scale_worst_case_setup, test_scale_worst_case_tear_down, MUNIT_TEST_OPTION_NONE, NULL },