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