-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbinmap.h
35 lines (24 loc) · 877 Bytes
/
binmap.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
#ifndef __binmap_H__
#define __binmap_H__
#include <stdint.h>
/* Structure of one hash table entry. */
typedef struct binmap_entry_s binmap_entry_t;
struct binmap_entry_s {
int64_t key; /* lookup key */
void *value; /* associated value */
binmap_entry_t *next; /* colliding entry */
binmap_entry_t *prev; /* colliding entry */
};
/* Structure of one hash table. */
typedef struct {
int64_t size; /* length of entries array */
int32_t used; /* number of entries in table */
uint8_t idx; /* primes id */
binmap_entry_t **data; /* entries array, auto-resized */
} binmap_t;
binmap_t *binmap_create(int);
binmap_entry_t *binmap_insert(binmap_t *, int64_t, void *);
void *binmap_find(binmap_t * map, int64_t key);
void binmap_free(binmap_t * map, void (*free_value) (void *));
int binmap_delete(binmap_t * map, int64_t key, void (*free_fn) (char *));
#endif