Mercurial > hg > octave-lojdl > gnulib-hg
annotate lib/hash.h @ 1170:8de2d981b46f
Use PARAMS, not __P.
author | Jim Meyering <jim@meyering.net> |
---|---|
date | Sun, 21 Dec 1997 11:22:51 +0000 |
parents | c58834e11c55 |
children | 20f35a1b786a |
rev | line source |
---|---|
1032
0b6b7e10fe5f
use HASH_H, not _hash_h_ in #ifndef
Jim Meyering <jim@meyering.net>
parents:
1031
diff
changeset
|
1 #ifndef HASH_H |
0b6b7e10fe5f
use HASH_H, not _hash_h_ in #ifndef
Jim Meyering <jim@meyering.net>
parents:
1031
diff
changeset
|
2 # define HASH_H 1 |
0b6b7e10fe5f
use HASH_H, not _hash_h_ in #ifndef
Jim Meyering <jim@meyering.net>
parents:
1031
diff
changeset
|
3 |
0b6b7e10fe5f
use HASH_H, not _hash_h_ in #ifndef
Jim Meyering <jim@meyering.net>
parents:
1031
diff
changeset
|
4 # if HAVE_CONFIG_H |
0b6b7e10fe5f
use HASH_H, not _hash_h_ in #ifndef
Jim Meyering <jim@meyering.net>
parents:
1031
diff
changeset
|
5 # include <config.h> |
0b6b7e10fe5f
use HASH_H, not _hash_h_ in #ifndef
Jim Meyering <jim@meyering.net>
parents:
1031
diff
changeset
|
6 # endif |
1031 | 7 |
8 # include <stdio.h> | |
9 # include <assert.h> | |
10 | |
1032
0b6b7e10fe5f
use HASH_H, not _hash_h_ in #ifndef
Jim Meyering <jim@meyering.net>
parents:
1031
diff
changeset
|
11 # ifdef STDC_HEADERS |
0b6b7e10fe5f
use HASH_H, not _hash_h_ in #ifndef
Jim Meyering <jim@meyering.net>
parents:
1031
diff
changeset
|
12 # include <stdlib.h> |
1130
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
13 # endif |
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
14 |
1168
c58834e11c55
s/HAVE_DECLARATION_/HAVE_DECL_/.
Jim Meyering <jim@meyering.net>
parents:
1130
diff
changeset
|
15 # ifndef HAVE_DECL_FREE |
1032
0b6b7e10fe5f
use HASH_H, not _hash_h_ in #ifndef
Jim Meyering <jim@meyering.net>
parents:
1031
diff
changeset
|
16 void free (); |
1130
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
17 # endif |
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
18 |
1168
c58834e11c55
s/HAVE_DECLARATION_/HAVE_DECL_/.
Jim Meyering <jim@meyering.net>
parents:
1130
diff
changeset
|
19 # ifndef HAVE_DECL_MALLOC |
1032
0b6b7e10fe5f
use HASH_H, not _hash_h_ in #ifndef
Jim Meyering <jim@meyering.net>
parents:
1031
diff
changeset
|
20 char *malloc (); |
0b6b7e10fe5f
use HASH_H, not _hash_h_ in #ifndef
Jim Meyering <jim@meyering.net>
parents:
1031
diff
changeset
|
21 # endif |
0b6b7e10fe5f
use HASH_H, not _hash_h_ in #ifndef
Jim Meyering <jim@meyering.net>
parents:
1031
diff
changeset
|
22 |
1170 | 23 # ifndef PARAMS |
24 # if defined PROTOTYPES || (defined __STDC__ && __STDC__) | |
25 # define PARAMS(Args) Args | |
26 # else | |
27 # define PARAMS(Args) () | |
28 # endif | |
29 # endif | |
30 | |
1032
0b6b7e10fe5f
use HASH_H, not _hash_h_ in #ifndef
Jim Meyering <jim@meyering.net>
parents:
1031
diff
changeset
|
31 # define USE_OBSTACK |
1031 | 32 # ifdef USE_OBSTACK |
33 # include "obstack.h" | |
34 # endif | |
35 | |
1032
0b6b7e10fe5f
use HASH_H, not _hash_h_ in #ifndef
Jim Meyering <jim@meyering.net>
parents:
1031
diff
changeset
|
36 # define obstack_chunk_alloc malloc |
1031 | 37 # define obstack_chunk_free free |
38 | |
39 struct hash_ent | |
40 { | |
41 void *key; | |
42 struct hash_ent *next; | |
43 }; | |
44 typedef struct hash_ent HASH_ENT; | |
45 | |
46 /* This is particularly useful to cast uses in hash_initialize of the | |
47 system free function. */ | |
1130
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
48 typedef void (*Hash_key_freer_type) PARAMS((void *key)); |
1031 | 49 |
50 struct HT | |
51 { | |
52 /* User-supplied function for freeing keys. It is specified in | |
1032
0b6b7e10fe5f
use HASH_H, not _hash_h_ in #ifndef
Jim Meyering <jim@meyering.net>
parents:
1031
diff
changeset
|
53 hash_initialize. If non-null, it is used by hash_free and |
0b6b7e10fe5f
use HASH_H, not _hash_h_ in #ifndef
Jim Meyering <jim@meyering.net>
parents:
1031
diff
changeset
|
54 hash_clear. You should specify `free' here only if you want |
0b6b7e10fe5f
use HASH_H, not _hash_h_ in #ifndef
Jim Meyering <jim@meyering.net>
parents:
1031
diff
changeset
|
55 these functions to free all of your `key' data. This is typically |
0b6b7e10fe5f
use HASH_H, not _hash_h_ in #ifndef
Jim Meyering <jim@meyering.net>
parents:
1031
diff
changeset
|
56 the case when your key is simply an auxilliary struct that you |
0b6b7e10fe5f
use HASH_H, not _hash_h_ in #ifndef
Jim Meyering <jim@meyering.net>
parents:
1031
diff
changeset
|
57 have malloc'd to aggregate several values. */ |
1031 | 58 Hash_key_freer_type hash_key_freer; |
59 | |
60 /* User-supplied hash function that hashes entry E to an integer | |
61 in the range 0..TABLE_SIZE-1. */ | |
1130
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
62 unsigned int (*hash_hash) PARAMS((const void *e, unsigned int table_size)); |
1031 | 63 |
64 /* User-supplied function that determines whether a new entry is | |
65 unique by comparing the new entry to entries that hashed to the | |
66 same bucket index. It should return zero for a pair of entries | |
67 that compare equal, non-zero otherwise. */ | |
68 | |
1130
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
69 int (*hash_key_comparator) PARAMS((const void *, const void *)); |
1031 | 70 |
71 HASH_ENT **hash_table; | |
72 unsigned int hash_table_size; | |
73 unsigned int hash_n_slots_used; | |
74 unsigned int hash_max_chain_length; | |
75 | |
76 /* Gets set when an entry is deleted from a chain of length | |
77 hash_max_chain_length. Indicates that hash_max_chain_length | |
78 may no longer be valid. */ | |
79 unsigned int hash_dirty_max_chain_length; | |
80 | |
81 /* Sum of lengths of all chains (not counting any dummy | |
82 header entries). */ | |
83 unsigned int hash_n_keys; | |
84 | |
85 /* A linked list of freed HASH_ENT structs. | |
86 FIXME: Perhaps this is unnecessary and we should simply free | |
87 and reallocate such structs. */ | |
88 HASH_ENT *hash_free_entry_list; | |
89 | |
90 /* FIXME: comment. */ | |
91 # ifdef USE_OBSTACK | |
92 struct obstack ht_obstack; | |
93 # endif | |
94 }; | |
95 | |
96 typedef struct HT HT; | |
97 | |
98 unsigned int | |
1130
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
99 hash_get_n_slots_used PARAMS((const HT *ht)); |
1031 | 100 |
101 unsigned int | |
1130
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
102 hash_get_max_chain_length PARAMS((HT *ht)); |
1031 | 103 |
104 int | |
1130
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
105 hash_rehash PARAMS((HT *ht, unsigned int new_table_size)); |
1031 | 106 |
107 unsigned int | |
1130
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
108 hash_get_table_size PARAMS((const HT *ht)); |
1031 | 109 |
110 HT * | |
1130
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
111 hash_initialize PARAMS((unsigned int table_size, |
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
112 void (*key_freer) PARAMS((void *key)), |
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
113 unsigned int (*hash) PARAMS((const void *, |
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
114 unsigned int)), |
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
115 int (*equality_tester) PARAMS((const void *, |
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
116 const void *)))); |
1031 | 117 |
118 unsigned int | |
1130
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
119 hash_get_n_keys PARAMS((const HT *ht)); |
1031 | 120 |
121 int | |
1130
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
122 hash_query_in_table PARAMS((const HT *ht, const void *e)); |
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
123 |
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
124 void * |
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
125 hash_lookup PARAMS((const HT *ht, const void *e)); |
1031 | 126 |
127 void * | |
1130
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
128 hash_insert_if_absent PARAMS((HT *ht, |
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
129 const void *e, |
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
130 int *failed)); |
1031 | 131 |
132 void * | |
1130
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
133 hash_delete_if_present PARAMS((HT *ht, const void *e)); |
1031 | 134 |
135 void | |
1130
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
136 hash_print_statistics PARAMS((const HT *ht, FILE *stream)); |
1031 | 137 |
138 int | |
1130
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
139 hash_get_statistics PARAMS((const HT *ht, unsigned int *n_slots_used, |
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
140 unsigned int *n_keys, |
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
141 unsigned int *max_chain_length)); |
1031 | 142 |
143 int | |
1130
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
144 hash_table_ok PARAMS((HT *ht)); |
1031 | 145 |
146 void | |
1130
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
147 hash_do_for_each PARAMS((HT *ht, |
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
148 void (*f) PARAMS((void *e, void *aux)), |
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
149 void *aux)); |
1031 | 150 |
151 int | |
1130
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
152 hash_do_for_each_2 PARAMS((HT *ht, |
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
153 int (*f) PARAMS((void *e, void *aux)), |
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
154 void *aux)); |
1031 | 155 |
156 int | |
1130
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
157 hash_do_for_each_in_selected_bucket PARAMS((HT *ht, |
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
158 const void *key, |
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
159 int (*f) PARAMS((const void *bucket_key, |
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
160 void *e, |
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
161 void *aux)), |
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
162 void *aux)); |
1031 | 163 |
164 void | |
1130
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
165 hash_clear PARAMS((HT *ht)); |
1031 | 166 |
167 void | |
1130
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
168 hash_free PARAMS((HT *ht)); |
1031 | 169 |
170 void | |
1130
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
171 hash_get_key_list PARAMS((const HT *ht, |
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
172 unsigned int bufsize, |
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
173 void **buf)); |
1031 | 174 |
175 void * | |
1130
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
176 hash_get_first PARAMS((const HT *ht)); |
1031 | 177 |
178 void * | |
1130
aa231bb87550
add PARAMS around prototype lists
Jim Meyering <jim@meyering.net>
parents:
1032
diff
changeset
|
179 hash_get_next PARAMS((const HT *ht, const void *e)); |
1031 | 180 |
181 /* This interface to hash_insert_if_absent is used frequently enough to | |
182 merit a macro here. */ | |
183 | |
1032
0b6b7e10fe5f
use HASH_H, not _hash_h_ in #ifndef
Jim Meyering <jim@meyering.net>
parents:
1031
diff
changeset
|
184 # define HASH_INSERT_NEW_ITEM(Ht, Item, Failp) \ |
1031 | 185 do \ |
186 { \ | |
1032
0b6b7e10fe5f
use HASH_H, not _hash_h_ in #ifndef
Jim Meyering <jim@meyering.net>
parents:
1031
diff
changeset
|
187 void *_already; \ |
0b6b7e10fe5f
use HASH_H, not _hash_h_ in #ifndef
Jim Meyering <jim@meyering.net>
parents:
1031
diff
changeset
|
188 _already = hash_insert_if_absent ((Ht), (Item), Failp); \ |
0b6b7e10fe5f
use HASH_H, not _hash_h_ in #ifndef
Jim Meyering <jim@meyering.net>
parents:
1031
diff
changeset
|
189 assert (_already == NULL); \ |
1031 | 190 } \ |
191 while (0) | |
192 | |
1032
0b6b7e10fe5f
use HASH_H, not _hash_h_ in #ifndef
Jim Meyering <jim@meyering.net>
parents:
1031
diff
changeset
|
193 #endif /* HASH_H */ |