1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
/* Copyright (C) 1995, 2000-2003, 2005 Free Software Foundation, Inc.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 51 Franklin Street,
Fifth Floor, Boston, MA 02110-1301, USA. */
#ifndef _HASH_H
#define _HASH_H
#include "obstack.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct hash_table
{
unsigned long int size; /* Number of allocated entries. */
unsigned long int filled; /* Number of used entries. */
void *first; /* Pointer to head of list of entries. */
void *table; /* Pointer to array of entries. */
struct obstack mem_pool; /* Memory pool holding the keys. */
}
hash_table;
/* Initialize a hash table. INIT_SIZE > 1 is the initial number of available
entries.
Return 0 upon successful completion, -1 upon memory allocation error. */
extern int hash_init (hash_table *htab, unsigned long int init_size);
/* Delete a hash table's contents.
Return 0 always. */
extern int hash_destroy (hash_table *htab);
/* Look up the value of a key in the given table.
If found, return 0 and set *RESULT to it. Otherwise return -1. */
extern int hash_find_entry (hash_table *htab,
const void *key, size_t keylen,
void **result);
/* Try to insert the pair (KEY[0..KEYLEN-1], DATA) in the hash table.
Return non-NULL (more precisely, the address of the KEY inside the table's
memory pool) if successful, or NULL if there is already an entry with the
given key. */
extern const void * hash_insert_entry (hash_table *htab,
const void *key, size_t keylen,
void *data);
/* Insert the pair (KEY[0..KEYLEN-1], DATA) in the hash table.
Return 0. */
extern int hash_set_value (hash_table *htab,
const void *key, size_t keylen,
void *data);
/* Steps *PTR forward to the next used entry in the given hash table. *PTR
should be initially set to NULL. Store information about the next entry
in *KEY, *KEYLEN, *DATA.
Return 0. */
extern int hash_iterate (hash_table *htab, void **ptr,
const void **key, size_t *keylen,
void **data);
/* Given SEED > 1, return the smallest odd prime number >= SEED. */
extern unsigned long int next_prime (unsigned long int seed);
#ifdef __cplusplus
}
#endif
#endif /* not _HASH_H */
|