Debian Codegraph @

ext/GOTCHA/src/hash.h

raw symbols SCIP
1 /*
2 This file is part of GOTCHA. For copyright information see the COPYRIGHT
3 file in the top level directory, or at
4 https://github.com/LLNL/gotcha/blob/master/COPYRIGHT
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU Lesser General Public License (as published by the Free
7 Software Foundation) version 2.1 dated February 1999. This program is
8 distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 without even the IMPLIED WARRANTY OF MERCHANTABILITY or FITNESS FOR A PARTICULAR
10 PURPOSE. See the terms and conditions of the GNU Lesser General Public License
11 for more details. You should have received a copy of the GNU Lesser General
12 Public License along with this program; if not, write to the Free Software
13 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
14 */
15
16 #if !defined(HASH_H_)
17 #define HASH_H_
18
19 #include <stdint.h>
20 #include <stdlib.h>
21
22 typedef void *hash_key_t;
23 typedef void *hash_data_t;
24 typedef int hash_hashvalue_t;
25 typedef hash_hashvalue_t (*hash_func_t)(hash_data_t data);
26 typedef int (*hash_cmp_t)(hash_key_t a, hash_key_t b);
27
28 struct hash_entry_t;
29
30 typedef struct {
31 size_t table_size;
32 size_t entry_count;
33 hash_func_t hashfunc;
34 hash_cmp_t keycmp;
35 struct hash_entry_t *table;
36 struct hash_entry_t *head;
37 } hash_table_t;
38
39 int create_hashtable(hash_table_t *table, size_t initial_size, hash_func_t func,
40 hash_cmp_t keycmp);
41 int grow_hashtable(hash_table_t *table, size_t new_size);
42 int destroy_hashtable(hash_table_t *table);
43
44 int lookup_hashtable(hash_table_t *table, hash_key_t key, hash_data_t *data);
45 int addto_hashtable(hash_table_t *table, hash_key_t key, hash_data_t data);
46 int removefrom_hashtable(hash_table_t *table, hash_key_t key);
47 int foreach_hash_entry(hash_table_t *table, void *opaque,
48 int (*cb)(hash_key_t key, hash_data_t data,
49 void *opaque));
50
51 hash_hashvalue_t strhash(const char *str);
52
53 #endif