1 /*****************************************************************************/
2 /* LibreDWG - free implementation of the DWG file format */
3 /* */
4 /* Copyright (C) 2018-2019, 2023 Free Software Foundation, Inc. */
5 /* */
6 /* This library is free software, licensed under the terms of the GNU */
7 /* General Public License as published by the Free Software Foundation, */
8 /* either version 3 of the License, or (at your option) any later version. */
9 /* You should have received a copy of the GNU General Public License */
10 /* along with this program. If not, see <http://www.gnu.org/licenses/>. */
11 /*****************************************************************************/
12
13 #ifndef HASH_H
14 #define HASH_H
15
16 /*
17 * hash.h: simple fast int hashmap for the object_ref map,
18 * mapping uint64_t to uint64_t.
19 * 0 keys and values are disallowed even if there's no deletion.
20 * written by Reini Urban
21 */
22
23 #include "config.h"
24 #include <stdint.h>
25 #include <inttypes.h>
26
27 #define HASH_LOAD 75 // in percent. recommended is 50
28 #define HASH_NOT_FOUND (uint64_t) - 1
29
30 struct _hashbucket
31 {
32 uint64_t key;
33 uint64_t value;
34 };
35 typedef struct _inthash
36 {
37 struct _hashbucket *array; /* of key, value pairs */
38 uint64_t size;
39 uint64_t elems; // to get the fill rate
40 } dwg_inthash;
41
42 dwg_inthash *hash_new (uint64_t size);
43 uint64_t hash_get (dwg_inthash *hash, uint64_t key);
44 void hash_set (dwg_inthash *hash, uint64_t key, uint64_t value);
45 void hash_free (dwg_inthash *hash);
46
47 #endif