hash function
This commit is contained in:
@ -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);
|
||||
|
||||
@ -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
4
include/acl/hashmap.h
Normal file
@ -0,0 +1,4 @@
|
||||
#ifndef _acl_hashmap_h
|
||||
#define _acl_hashmap_h
|
||||
unsigned hash(unsigned K);
|
||||
#endif
|
||||
@ -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
6
src/hashmap.c
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user