hash function

This commit is contained in:
2020-07-22 22:11:05 +02:00
parent ff58a623fe
commit de2c53f473
5 changed files with 16 additions and 5 deletions

View File

@ -28,7 +28,8 @@ void* acl_arraylist_append(void *arraylist_void, void *element) {
union arraylist_meta *arraylist = arraylist_void;
--arraylist;
if(arraylist->len == arraylist->cap) {
arraylist->cap = arraylist->len + 10;
if(arraylist->len > 10) arraylist->cap = arraylist->len + 10;
else arraylist->cap = arraylist->len * 2;
arraylist = realloc(arraylist, arraylist->cap * arraylist->sizeof_one_element + sizeof *arraylist);
if(!arraylist) return NULL;
}

6
src/hashmap.c Normal file
View File

@ -0,0 +1,6 @@
#include <math.h>
const unsigned acl_w = sizeof (unsigned) * 8;
const unsigned acl_m = 9;
unsigned hash(unsigned K) {
return (149695736*K) >> (acl_w-acl_m);
}