-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflmap.h
42 lines (34 loc) · 1.13 KB
/
flmap.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
#ifndef FLMAP_H
#define FLMAP_H
#include <stdlib.h>
#include <stdio.h>
enum {
E, // empty
L, // occupied: index==hash(key)
S // rellocated: index!=hash(key)
};
typedef struct FLNode{
unsigned char type; // how the node is used (E, L, S)
int links[3]; // 0=prev/left, 1=next/right, 2=parent
struct { // user data
size_t key;
void* value;
} pair;
}FLNode; // 24 on x86, 32 on x64
typedef struct FLHashMap{
FLNode* table; // hash table
int free_list; // list of free nodes (link to first free node)
int N; // number of items in table
int T; // table size
int R; // Hopscotch Region
}FLHashMap;
FLHashMap* FLHashMap_new();
void FLHashMap_destroy(FLHashMap* self);
void FLHashMap_destroyCB(FLHashMap* self, void (*callback)(size_t key, void* value));
void* FLHashMap_set(FLHashMap* self, size_t key, void* value);
void* FLHashMap_get(FLHashMap* self, size_t key);
void* FLHashMap_del(FLHashMap* self, size_t key);
void FLHashMap_forEach(FLHashMap* self, void (*callback)(size_t key, void* value));
void FLHashMap_print(FLHashMap* self);
void FLHashMap_printStats(FLHashMap* self);
#endif