diff --git a/simap.h b/simap.h index bdeff42..2955228 100644 --- a/simap.h +++ b/simap.h @@ -25,11 +25,11 @@ typedef union simap_ptr64 simap_ptr64; * * XXX: So beware that this can FAIL just "statistically most often works"! * - * The memory layout after at *base is as follows: + * The per-elem memory layout after at *base is as follows: * * 8 byte: * - void* value; - * - ? padding (only for non-64 bit pointer machines) + * - [?] optional padding (only for non-64 bit pointer machines) * * 8 byte: * - uint32_t previndex; @@ -39,8 +39,6 @@ typedef union simap_ptr64 simap_ptr64; * - char name[]; // inline stored * - padding (divisible by 8) * - * ELEMENTS added to it... - * * Because of it a lookup is basically via strstr-like with 8byte steps! * with few character names zero-padded in the search term parameter * and if you want check extra validity by jumping back&forth in it. @@ -50,7 +48,6 @@ struct simap_instance { uint32_t end; uint32_t prev_usage_end; /* previous usage_end or -1 if no previous exists... in bytes!!! */ uint32_t usage_end; /* in bytes!!! */ - uint32_t next_previndex; /* in bytes!!! */ /** see doc comment for layout and why uint64_t* is the type */ uint64_t *base; }; @@ -62,7 +59,6 @@ static inline simap_instance simap_create() { ret.end = 0; ret.prev_usage_end = (uint32_t) -1; ret.usage_end = 0; - ret.next_previndex = 0; ret.base = ((uint64_t*) aralloc(&(ret.a), sizeof(uint64_t), sizeof(uint64_t), 1)) /* addr divisible by 8 */ + 1; /* First really addressible thing */ return ret; @@ -182,9 +178,8 @@ static inline void *simap_force_add_internal(simap_instance *map, const char *ke data->ptr = ptr; /* Save link to previous */ - uint32_t *usprev = (uint32_t *)((uint8_t *)(map->base) + - sizeof(simap_ptr64) + - sizeof(uint32_t)); + uint32_t *usprev = (uint32_t *)((uint8_t *)(map->base) + usi + + sizeof(simap_ptr64)); *usprev = previ; /* and nex */ *(usprev + 1) = (uint32_t) -1; @@ -193,8 +188,8 @@ static inline void *simap_force_add_internal(simap_instance *map, const char *ke simap_c64 *start_str = (simap_c64 *)(usprev + 2); *start_str = first8; - /* Remainin bytes */ - if(keylen > 8) { + /* Remaining bytes */ + if(keylen >= 8) { /* uint32_t key_remains = keylen - 8; */ char *rem_str = (char *)(start_str + 1); strcpy(rem_str, key + 8);