better hashing
This commit is contained in:
@ -9,6 +9,7 @@ union acl_hashmap_meta {
|
|||||||
size_t keyBits;
|
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);
|
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);
|
void acl_hashmap_put(union acl_hashmap_meta *hashmap_meta, void *key, void *element);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -42,7 +42,7 @@ void* acl_arraylist_append_ptr(void *arraylist_void, void **append_element) {
|
|||||||
if(arraylist->len > 10) arraylist->cap = arraylist->len + 10;
|
if(arraylist->len > 10) arraylist->cap = arraylist->len + 10;
|
||||||
else arraylist->cap = arraylist->len * 2 + 1;
|
else arraylist->cap = arraylist->len * 2 + 1;
|
||||||
arraylist = realloc(arraylist, arraylist->cap * arraylist->sizeof_one_element + sizeof *arraylist);
|
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;
|
*append_element = (char*)(arraylist + 1) + arraylist->sizeof_one_element * arraylist->len;
|
||||||
++arraylist->len;
|
++arraylist->len;
|
||||||
|
|||||||
@ -7,18 +7,8 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#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)\
|
#define acl_hashVarLen(type)\
|
||||||
if(((uintptr_t)data & (alignof(type) - 1)) == 0) {\
|
if(((uintptr_t)data & (alignof(type) - 1)) == 0) {\
|
||||||
printf(#type);\
|
|
||||||
type *src;\
|
type *src;\
|
||||||
for(uint64_t *keySrc = data; (char*)(keySrc + 1) <= dest; ++keySrc) {\
|
for(uint64_t *keySrc = data; (char*)(keySrc + 1) <= dest; ++keySrc) {\
|
||||||
src = (type*)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);
|
void **hashmap_buckets = (void**)(hashmap_meta + 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
#include <stdio.h>
|
|
||||||
int main() {
|
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));
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user