-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFlatChainedHashTable.h
65 lines (50 loc) · 1.15 KB
/
FlatChainedHashTable.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
64
65
#ifndef _FLAT_CHAINED_HASH_TABLE_
#define _FLAT_CHAINED_HASH_TABLE_
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef union {
double dbl;
int64_t i64;
uint64_t u64;
void* ptr;
}element_t;
typedef struct {
uint64_t meta;
uint64_t key;
element_t value;
}map_bucket_t;
typedef struct {
uint64_t count;
uint64_t shift;
uint64_t mask;
uint64_t capacity;
}hashtable_t;
typedef struct {
hashtable_t hashtable;
map_bucket_t buckets[];
}map_t;
typedef struct {
uint64_t meta;
uint64_t key;
}set_bucket_t;
typedef struct {
hashtable_t hashtable;
set_bucket_t buckets[];
}set_t;
float hashtable_load_factor(const hashtable_t* hashtable);
map_t *map_create(uint64_t initial_capacity);
void map_destroy(map_t **map);
element_t *map_get(map_t *map, const uint64_t key);
bool map_put(map_t **map, uint64_t key, element_t value);
void map_del(map_t **map, uint64_t key);
#ifdef __cplusplus
};
#endif
static inline float map_load_factor(const map_t *map){return hashtable_load_factor((hashtable_t*)map);}
#endif