lib: hash: Ensure OA/LP hmap inserts don't return tombstones

According to the hashmap interface specification sys_hashmap_remove will
"Erase the entry associated with key `key`, if one exists"

If a rehash is performed OA/LP will return 1 and no old_value for
sys_hashmap_insert.

If a rehash is NOT performed OA/LP will return 0 and a stale old_value for
sys_hashmap_insert even though the user requested the entry for that key to
be removed.

This patch makes OA/LP not return the value of tombstoned entries.

Signed-off-by: Emil Hammarstrom <emil.hammarstrom1@assaabloy.com>
This commit is contained in:
Emil Hammarstrom
2025-09-23 16:15:54 +02:00
committed by Fabio Baltieri
parent 48059d126b
commit 12986286de

View File

@@ -84,23 +84,22 @@ static int sys_hashmap_oa_lp_insert_no_rehash(struct sys_hashmap *map, uint64_t
__ASSERT_NO_MSG(entry != NULL);
switch (entry->state) {
case UNUSED:
++data->size;
ret = 1;
break;
case TOMBSTONE:
--data->n_tombstones;
++data->size;
ret = 0;
ret = 1;
break;
case USED:
default:
if (old_value != NULL) {
*old_value = entry->value;
}
ret = 0;
break;
}
if (old_value != NULL) {
*old_value = entry->value;
case UNUSED:
default:
++data->size;
ret = 1;
break;
}
entry->state = USED;