better growth

This commit is contained in:
Richard Thier 2024-09-30 12:08:31 +02:00
parent 67e2652363
commit 2cdcdc167f
2 changed files with 11 additions and 3 deletions

@ -1 +1 @@
Subproject commit 70f97b8291454efbf9606051352c15ea6ebca319
Subproject commit 3037bf6bec96b0ebc231510d308da1daece276fd

12
simap.h
View File

@ -144,10 +144,16 @@ static inline uint32_t simap_elem_storage_size(const char *key) {
/** Force-add the (key,value) to the end of the map */
static inline void *simap_force_add_internal(simap_instance *map, const char *key, void *ptr) {
uint32_t storage_needed = simap_elem_storage_size(key);
assert((storage_needed & 8) == 0);
if(map->end - map->usage_end > storage_needed) {
/* Need storage */
/* TODO: Implement */
// Soemthin' like = ((T*) alloc(&a, sizeof(T), sizeof(T), 1)) + 1;
aralloc(&(map->a),
sizeof(uint8_t)/*esize*/,
1 /*align - should be 8 but should be aligned here as-is! */,
storage_needed);
/* Administer end offset */
map->end += storage_needed;
}
/* Already have the storage */
@ -191,9 +197,11 @@ static inline void* simap(void *amap_instance, AMAP_OP op, const char *key, void
found->ptr = ptr;
return (void *) found;
} else {
return simap_force_add_internal(map, key, ptr);
}
}
assert(false); /* should be unreachable */
return NULL;
}