-
Notifications
You must be signed in to change notification settings - Fork 64
/
hash.h
45 lines (37 loc) · 1.02 KB
/
hash.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
#ifndef HASH_H
#define HASH_H
#if !defined(INTERNAL) || !defined(EXTERNAL)
# error Missing amalgamation macros
#endif
#include "string.h"
struct hash_table {
int capacity;
int count;
struct hash_entry *entries;
};
/* Reset table, clearing all values. Does not deallocate memory. */
INTERNAL void hash_clear(struct hash_table *tab, void (*del)(void *));
/* Free resources owned by table. */
INTERNAL void hash_destroy(struct hash_table *tab);
/*
* Insert element, or return existing with the same key.
*
* Initializer, if provided, is invoked when data is added.
*/
INTERNAL void *hash_insert(
struct hash_table *tab,
String key,
void *value,
void *(*add)(void *, String *));
/* Retrieve element matching key, or NULL if not found. */
INTERNAL void *hash_lookup(struct hash_table *tab, String key);
/*
* Remove element matching key.
*
* Finalizer, if provider, is invoked when data is removed.
*/
INTERNAL void hash_remove(
struct hash_table *tab,
String key,
void (*del)(void *));
#endif