From ac62753820e5811055c2b8d40e30822871a95541 Mon Sep 17 00:00:00 2001 From: Richard Thier Date: Wed, 23 Oct 2024 00:45:33 +0200 Subject: [PATCH] multimap ops tests and some cleanup - seems workin" --- main.cpp | 16 ++++++++++++++-- simap.h | 4 ++-- simd_map.h | 4 ++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/main.cpp b/main.cpp index c01e25a..43d2d3a 100644 --- a/main.cpp +++ b/main.cpp @@ -181,7 +181,7 @@ void test_simd_map_basics() { for(int i = 0; i < cnt; ++i) { assert(simd_map_set(&smap, i, (cnt - i)) != 0); } - assert(simd_map_size(&smap) == 100); // 42->2 should get overwritten + assert(simd_map_size(&smap) == 100); /* 42->2 should get overwritten */ for(int i = 0; i < cnt; ++i) { assert(*simd_map_find(&smap, i) == (uint32_t)(cnt - i)); } @@ -196,7 +196,19 @@ void test_simd_map_basics() { assert(simd_map_find(&smap, 98) != NULL); assert(simd_map_size(&smap) == 98); - /* Filled free */ + /* Test multimap operations */ + assert(simd_map_multi_set(&smap, 42, 42) != 0); + assert(simd_map_find(&smap, 42) != NULL); + assert(*simd_map_find(&smap, 42) != 42); + simd_map_find_res res1 = simd_map_find_all(&smap, 42, simd_map_find_all_begin()); + assert(res1.value_location != NULL); + assert(*(res1.value_location) != 42); + simd_map_find_res res2 = simd_map_find_all(&smap, 42, res1); + assert(*(res2.value_location) == 42); + simd_map_find_res res3 = simd_map_find_all(&smap, 42, res2); + assert(res3.value_location == NULL); + + /* Test filled-free */ simd_map_free(&smap); } diff --git a/simap.h b/simap.h index 319bc20..054a8a2 100644 --- a/simap.h +++ b/simap.h @@ -135,7 +135,7 @@ static inline unsigned int get_size_padding(unsigned int size, unsigned int alig /** Gets padded address - or same address if divisible by alignment */ static inline void *get_padded(void *ptr, int alignment) { - // return (alignment - (ptr % alignment)) % alignment; + /* return (alignment - (ptr % alignment)) % alignment; */ return (void*)((ptrdiff_t)((uint8_t *)ptr + alignment - 1) / alignment * alignment); } @@ -231,7 +231,7 @@ static inline simap_ptr64 *simap_search_internal(simap_instance *map, const char auint64 *base = (auint64 *) (map->base); auint64 *end = (auint64 *)((uint8_t *)base + (map->usage_end)); auint64 *tipp = make_tipp(base, base, prefix.u64, end); - while(tipp < end) { // XXX: (***) + while(tipp < end) { /* XXX: (***) */ /* Need detailed lookup, because found the prefix */ assert((*tipp == prefix.u64)); diff --git a/simd_map.h b/simd_map.h index 804a455..acb8ab1 100644 --- a/simd_map.h +++ b/simd_map.h @@ -215,7 +215,7 @@ static inline uint32_t *simd_map_find(simd_map *map, uint32_t key) { * @param value The value for this key to insert * @returns 0 on errors, otherwise 1. */ -static inline SM_ALWAYS_INLINE char simd_map_multi_insert(simd_map *map, uint32_t key, uint32_t value) { +static inline SM_ALWAYS_INLINE char simd_map_multi_set(simd_map *map, uint32_t key, uint32_t value) { /* Handle storage growth needs. */ uint32_t storage_needed = (map->lane_modulo == 0) ? 1 : 0; if(SM_UNLIKELY(map->end - map->usage_end < storage_needed)) { @@ -253,7 +253,7 @@ static inline SM_ALWAYS_INLINE char simd_map_multi_insert(simd_map *map, uint32_ static inline char simd_map_set(simd_map *map, uint32_t key, uint32_t value) { uint32_t *found = simd_map_find(map, key); if(!found) { - return simd_map_multi_insert(map, key, value); + return simd_map_multi_set(map, key, value); } else { /* Overwrite already existing mapping */ *found = value;