test: nasm-t -- Update multisection
[nasm.git] / include / hashtbl.h
blob239f61048fae7d02c631437df0f4bdbaf088efff
1 /* ----------------------------------------------------------------------- *
2 *
3 * Copyright 1996-2018 The NASM Authors - All Rights Reserved
4 * See the file AUTHORS included with the NASM distribution for
5 * the specific copyright holders.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following
9 * conditions are met:
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * ----------------------------------------------------------------------- */
35 * hashtbl.h
37 * Efficient dictionary hash table class.
40 #ifndef NASM_HASHTBL_H
41 #define NASM_HASHTBL_H
43 #include <stddef.h>
44 #include "nasmlib.h"
46 struct hash_node {
47 uint64_t hash;
48 const void *key;
49 size_t keylen;
50 void *data;
53 struct hash_table {
54 struct hash_node *table;
55 size_t load;
56 size_t size;
57 size_t max_load;
60 struct hash_insert {
61 struct hash_table *head;
62 struct hash_node *where;
63 struct hash_node node;
66 struct hash_iterator {
67 const struct hash_table *head;
68 const struct hash_node *next;
71 uint64_t crc64(uint64_t crc, const char *string);
72 uint64_t crc64i(uint64_t crc, const char *string);
73 uint64_t crc64b(uint64_t crc, const void *data, size_t len);
74 uint64_t crc64ib(uint64_t crc, const void *data, size_t len);
75 #define CRC64_INIT UINT64_C(0xffffffffffffffff)
77 void **hash_find(struct hash_table *head, const char *string,
78 struct hash_insert *insert);
79 void **hash_findb(struct hash_table *head, const void *key, size_t keylen,
80 struct hash_insert *insert);
81 void **hash_findi(struct hash_table *head, const char *string,
82 struct hash_insert *insert);
83 void **hash_findib(struct hash_table *head, const void *key, size_t keylen,
84 struct hash_insert *insert);
85 void **hash_add(struct hash_insert *insert, const void *key, void *data);
86 static inline void hash_iterator_init(const struct hash_table *head,
87 struct hash_iterator *iterator)
89 iterator->head = head;
90 iterator->next = head->table;
92 const struct hash_node *hash_iterate(struct hash_iterator *iterator);
94 #define hash_for_each(_head,_it,_np) \
95 for (hash_iterator_init((_head), &(_it)), (_np) = hash_iterate(&(_it)) ; \
96 (_np) ; (_np) = hash_iterate(&(_it)))
98 void hash_free(struct hash_table *head);
99 void hash_free_all(struct hash_table *head, bool free_keys);
101 #endif /* NASM_HASHTBL_H */