From 14009a6e2502c75d5ecb9c178ca891476394c7f6 Mon Sep 17 00:00:00 2001 From: MrGeorgen Date: Sun, 2 Aug 2020 15:11:32 +0200 Subject: [PATCH] better hashing --- include/acl/hashmap.h | 1 + src/array.c | 2 +- src/hashmap.c | 19 ------------------- 3 files changed, 2 insertions(+), 20 deletions(-) diff --git a/include/acl/hashmap.h b/include/acl/hashmap.h index d1cc7c3..70c999c 100644 --- a/include/acl/hashmap.h +++ b/include/acl/hashmap.h @@ -9,6 +9,7 @@ union acl_hashmap_meta { size_t keyBits; }; }; +/* set keySize to NULL for a dynamic keySize */ union acl_hashmap_meta* acl_hashmap_create(size_t bucketCount, size_t sizeOneElement, size_t keySize); void acl_hashmap_put(union acl_hashmap_meta *hashmap_meta, void *key, void *element); #endif diff --git a/src/array.c b/src/array.c index 615b0ce..4e0cdaf 100644 --- a/src/array.c +++ b/src/array.c @@ -42,7 +42,7 @@ void* acl_arraylist_append_ptr(void *arraylist_void, void **append_element) { if(arraylist->len > 10) arraylist->cap = arraylist->len + 10; else arraylist->cap = arraylist->len * 2 + 1; arraylist = realloc(arraylist, arraylist->cap * arraylist->sizeof_one_element + sizeof *arraylist); - if(!arraylist) return NULL; + if(arraylist == NULL) return NULL; } *append_element = (char*)(arraylist + 1) + arraylist->sizeof_one_element * arraylist->len; ++arraylist->len; diff --git a/src/hashmap.c b/src/hashmap.c index d16afd3..00273a7 100644 --- a/src/hashmap.c +++ b/src/hashmap.c @@ -7,18 +7,8 @@ #include #include #include -#ifdef ACL_LITTLE_ENDIAN -#define LEFT_OR_RIGHT_SHIFT >> -#else -#ifdef ACL_BIG_ENDIAN -#define LEFT_OR_RIGHT_SHIFT << -#else -#error "endianiss not specified. make sure to properly add the cmake subdirectory." -#endif -#endif #define acl_hashVarLen(type)\ if(((uintptr_t)data & (alignof(type) - 1)) == 0) {\ - printf(#type);\ type *src;\ for(uint64_t *keySrc = data; (char*)(keySrc + 1) <= dest; ++keySrc) {\ src = (type*)keySrc;\ @@ -79,14 +69,5 @@ void acl_hashmap_put(union acl_hashmap_meta *hashmap_meta, void *key, void *elem void **hashmap_buckets = (void**)(hashmap_meta + 1); } -#include int main() { - char baum[10] = {1}; - char blau[10] = {1}; - char green[10] = {1}; - char w[10] = {1}; - printf("Hash: %lu\n", acl_hash(baum, 9 * sizeof *baum , 5)); - printf("Hash: %lu\n", acl_hash(blau, 9 * sizeof *baum , 5)); - printf("Hash: %lu\n", acl_hash(green, 9 * sizeof *baum , 5)); - printf("Hash: %lu\n", acl_hash(w, 9 * sizeof *baum , 5)); }