File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change 6
6
#define HT_N_INLINE 32
7
7
8
8
#include "analyzer_annotations.h"
9
+ #include <stddef.h>
9
10
10
11
#ifdef __cplusplus
11
12
extern "C" {
12
13
#endif
13
14
15
+ // Power-of-two hash table with linear probing.
16
+ //
17
+ // Keys and values are stored as in consecutive elements
18
+ // key = table[2*i]
19
+ // value = table[2*i+1]
20
+ // where `2*i < size`. An empty slot at index `i` is indicated with
21
+ // `value == HT_NOTFOUND`.
22
+ //
23
+ // `_space` is reserved space for efficiently allocating small tables.
14
24
typedef struct {
15
25
size_t size ;
16
26
void * * table ;
@@ -20,13 +30,15 @@ typedef struct {
20
30
// define this to be an invalid key/value
21
31
#define HT_NOTFOUND ((void*)1)
22
32
23
- // initialize and free
33
+ // initialize hash table, reserving space for `size` expected number of
34
+ // elements. (Expect `h->size > size` for efficient occupancy factor.)
24
35
htable_t * htable_new (htable_t * h , size_t size );
25
36
void htable_free (htable_t * h );
26
37
27
38
// clear and (possibly) change size
28
39
void htable_reset (htable_t * h , size_t sz );
29
40
41
+ // Lookup and mutation. See htable.inc for detail.
30
42
#define HTPROT (HTNAME ) \
31
43
void *HTNAME##_get(htable_t *h, void *key) JL_NOTSAFEPOINT; \
32
44
void HTNAME##_put(htable_t *h, void *key, void *val) JL_NOTSAFEPOINT; \
You can’t perform that action at this time.
0 commit comments