-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhash_map.h
63 lines (49 loc) · 1.33 KB
/
hash_map.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef HASH_MAP_H
#define HASH_MAP_H
#include <stdlib.h>
#include <string.h>
#ifdef __cplusplus
extern "C"
{
#endif
#define HM_ERR_ALLOC 1
#define HM_W_NOTFOUND 2
#define DEFAULT_LOAD_FACTOR 0.75
#define DEFAULT_LEN 10
#define HM_NORMAL 0
#define HM_FAST 1
#define HM_DESTROY 2
/* stdbool.h is not required by C89 */
typedef unsigned char bool;
#define false 0
#define true !false
typedef struct node node;
struct node
{
void* key;
void* value;
node* next;
};
typedef struct hash_map hash_map;
struct hash_map
{
node** table;
unsigned long int(* hash_fn)(void* key);
bool(* eq_fn)(void* p1, void* p2);
unsigned long int table_len;
float load_factor;
unsigned long int element_ct;
};
short int hash_map_init(hash_map* map, unsigned long int(* hash_fn)(void* key), bool(* eq_fn)(void* p1, void* p2), unsigned long int start_len, float load_factor);
void hash_map_destroy(hash_map* map, unsigned short int flags);
short int hash_map_put(hash_map* map, void* key, void* value, unsigned short int flags);
void* hash_map_get(hash_map* map, void* key, unsigned short int flags);
short int hash_map_drop(hash_map* map, void* key, unsigned short int flags);
unsigned long int default_hash(void* key);
unsigned long int string_hash(void* key);
bool default_eq(void* p1, void* p2);
bool string_eq(void* p1, void* p2);
#ifdef __cplusplus
}
#endif
#endif