multimap ops tests and some cleanup - seems workin"

This commit is contained in:
Richard Thier 2024-10-23 00:45:33 +02:00
parent d219203939
commit ac62753820
3 changed files with 18 additions and 6 deletions

View File

@ -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);
}

View File

@ -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));

View File

@ -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;