Add test from BR 2690688
[platform/upstream/nasm.git] / hashtbl.h
1 /*
2  * hashtbl.h
3  *
4  * Efficient dictionary hash table class.
5  */
6
7 #ifndef NASM_HASHTBL_H
8 #define NASM_HASHTBL_H
9
10 #include <inttypes.h>
11 #include <stddef.h>
12 #include "nasmlib.h"
13
14 struct hash_tbl_node {
15     uint64_t hash;
16     const char *key;
17     void *data;
18 };
19
20 struct hash_table {
21     struct hash_tbl_node *table;
22     size_t load;
23     size_t size;
24     size_t max_load;
25 };
26
27 struct hash_insert {
28     uint64_t hash;
29     struct hash_table *head;
30     struct hash_tbl_node *where;
31 };
32
33 uint64_t crc64(uint64_t crc, const char *string);
34 uint64_t crc64i(uint64_t crc, const char *string);
35 #define CRC64_INIT UINT64_C(0xffffffffffffffff)
36
37 /* Some reasonable initial sizes... */
38 #define HASH_SMALL      4
39 #define HASH_MEDIUM     16
40 #define HASH_LARGE      256
41
42 void hash_init(struct hash_table *head, size_t size);
43 void **hash_find(struct hash_table *head, const char *string,
44                 struct hash_insert *insert);
45 void **hash_findi(struct hash_table *head, const char *string,
46                 struct hash_insert *insert);
47 void **hash_add(struct hash_insert *insert, const char *string, void *data);
48 void *hash_iterate(const struct hash_table *head,
49                    struct hash_tbl_node **iterator,
50                    const char **key);
51 void hash_free(struct hash_table *head);
52
53 #endif /* NASM_HASHTBL_H */