1 /* Copyright (C) 1995, 2000-2003, 2005-2006, 2015 Free Software
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
28 typedef struct hash_table
30 unsigned long int size; /* Number of allocated entries. */
31 unsigned long int filled; /* Number of used entries. */
32 struct hash_entry *first; /* Pointer to head of list of entries. */
33 struct hash_entry *table; /* Pointer to array of entries. */
34 struct obstack mem_pool; /* Memory pool holding the keys. */
38 /* Initialize a hash table. INIT_SIZE > 1 is the initial number of available
40 Return 0 upon successful completion, -1 upon memory allocation error. */
41 extern int hash_init (hash_table *htab, unsigned long int init_size);
43 /* Delete a hash table's contents.
45 extern int hash_destroy (hash_table *htab);
47 /* Look up the value of a key in the given table.
48 If found, return 0 and set *RESULT to it. Otherwise return -1. */
49 extern int hash_find_entry (hash_table *htab,
50 const void *key, size_t keylen,
53 /* Try to insert the pair (KEY[0..KEYLEN-1], DATA) in the hash table.
54 Return non-NULL (more precisely, the address of the KEY inside the table's
55 memory pool) if successful, or NULL if there is already an entry with the
57 extern const void * hash_insert_entry (hash_table *htab,
58 const void *key, size_t keylen,
61 /* Insert the pair (KEY[0..KEYLEN-1], DATA) in the hash table.
63 extern int hash_set_value (hash_table *htab,
64 const void *key, size_t keylen,
67 /* Steps *PTR forward to the next used entry in the given hash table. *PTR
68 should be initially set to NULL. Store information about the next entry
69 in *KEY, *KEYLEN, *DATA.
70 Return 0 normally, -1 when the whole hash table has been traversed. */
71 extern int hash_iterate (hash_table *htab, void **ptr,
72 const void **key, size_t *keylen,
75 /* Steps *PTR forward to the next used entry in the given hash table. *PTR
76 should be initially set to NULL. Store information about the next entry
77 in *KEY, *KEYLEN, *DATAP. *DATAP is set to point to the storage of the
78 value; modifying **DATAP will modify the value of the entry.
79 Return 0 normally, -1 when the whole hash table has been traversed. */
80 extern int hash_iterate_modify (hash_table *htab, void **ptr,
81 const void **key, size_t *keylen,
84 /* Given SEED > 1, return the smallest odd prime number >= SEED. */
85 extern unsigned long int next_prime (unsigned long int seed);
91 #endif /* not _HASH_H */