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

@ -1,5 +1,5 @@
#ifndef array_h
#define array_h
#ifndef _acl_array_h
#define _acl_array_h
#include <stddef.h>
size_t acl_arraylist_len(void *arraylist);
void acl_arraylist_free(void *arraylist);

View File

@ -1,5 +1,5 @@
#ifndef acl_file_h
#define acl_file_h
#ifndef _acl_file_h
#define _acl_file_h
#include <stdbool.h>
char* acl_ReadTextFile(const char *filePath, bool *sucess);
#endif

4
include/acl/hashmap.h Normal file
View File

@ -0,0 +1,4 @@
#ifndef _acl_hashmap_h
#define _acl_hashmap_h
unsigned hash(unsigned K);
#endif

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);
}