Skip to content

Commit fb1970c

Browse files
committed
Some comments about how to use htable_t
1 parent ab0f330 commit fb1970c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/support/htable.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,21 @@
66
#define HT_N_INLINE 32
77

88
#include "analyzer_annotations.h"
9+
#include <stddef.h>
910

1011
#ifdef __cplusplus
1112
extern "C" {
1213
#endif
1314

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.
1424
typedef struct {
1525
size_t size;
1626
void **table;
@@ -20,13 +30,15 @@ typedef struct {
2030
// define this to be an invalid key/value
2131
#define HT_NOTFOUND ((void*)1)
2232

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.)
2435
htable_t *htable_new(htable_t *h, size_t size);
2536
void htable_free(htable_t *h);
2637

2738
// clear and (possibly) change size
2839
void htable_reset(htable_t *h, size_t sz);
2940

41+
// Lookup and mutation. See htable.inc for detail.
3042
#define HTPROT(HTNAME) \
3143
void *HTNAME##_get(htable_t *h, void *key) JL_NOTSAFEPOINT; \
3244
void HTNAME##_put(htable_t *h, void *key, void *val) JL_NOTSAFEPOINT; \

0 commit comments

Comments
 (0)