1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
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/>. */
23 typedef int hsh_compare_func (const void *, const void *, const void *aux);
24 typedef unsigned hsh_hash_func (const void *, const void *aux);
25 typedef void hsh_free_func (void *, const void *aux);
27 /* Hash table iterator (opaque). */
30 size_t next; /* Index of next entry. */
34 unsigned hsh_hash_bytes (const void *, size_t);
35 unsigned hsh_hash_string (const char *);
36 unsigned hsh_hash_case_string (const char *);
37 unsigned hsh_hash_int (int);
38 unsigned hsh_hash_double (double);
41 struct hsh_table *hsh_create (int m, hsh_compare_func *,
42 hsh_hash_func *, hsh_free_func *,
46 struct hsh_table *hsh_create_pool (struct pool *pool, int m,
48 hsh_hash_func *, hsh_free_func *,
51 void hsh_clear (struct hsh_table *);
52 void hsh_destroy (struct hsh_table *);
53 void *const *hsh_sort (struct hsh_table *);
54 void *const *hsh_data (struct hsh_table *);
55 void **hsh_sort_copy (struct hsh_table *);
56 void **hsh_data_copy (struct hsh_table *);
58 /* Search and insertion. */
59 void **hsh_probe (struct hsh_table *, const void *);
60 void *hsh_insert (struct hsh_table *, void *);
61 void *hsh_replace (struct hsh_table *, void *);
62 void *hsh_find (struct hsh_table *, const void *);
63 bool hsh_delete (struct hsh_table *, const void *);
66 void *hsh_first (struct hsh_table *, struct hsh_iterator *);
67 void *hsh_next (struct hsh_table *, struct hsh_iterator *);
69 /* Search and insertion with assertion. */
71 void hsh_force_insert (struct hsh_table *, void *);
72 void *hsh_force_find (struct hsh_table *, const void *);
73 void hsh_force_delete (struct hsh_table *, const void *);
75 #define hsh_force_insert(A, B) ((void) (*hsh_probe (A, B) = B))
76 #define hsh_force_find(A, B) (hsh_find (A, B))
77 #define hsh_force_delete(A, B) ((void) hsh_delete (A, B))
80 /* Number of entries in hash table H. */
81 size_t hsh_count (struct hsh_table *);
85 void hsh_dump (struct hsh_table *);
89 /* Const Wrappers for the above */
91 static inline struct const_hsh_table *
92 const_hsh_create (int m,
93 hsh_compare_func *hcf,
94 hsh_hash_func *hhf, hsh_free_func *hff,
97 return (struct const_hsh_table *) hsh_create (m, hcf, hhf, hff, aux);
102 static inline struct const_hsh_table *
103 const_hsh_create_pool (struct pool *pool, int m,
104 hsh_compare_func *cf,
105 hsh_hash_func *hf, hsh_free_func *ff,
108 return (struct const_hsh_table *) hsh_create_pool (pool, m, cf, hf, ff, aux);
113 const_hsh_clear (struct const_hsh_table *h)
115 hsh_clear ( (struct hsh_table *) h);
119 const_hsh_destroy (struct const_hsh_table *h)
121 hsh_destroy ( (struct hsh_table *) h);
124 static inline void *const *
125 const_hsh_sort (struct const_hsh_table *h)
127 return hsh_sort ( (struct hsh_table *) h);
130 static inline void *const *
131 const_hsh_data (struct const_hsh_table *h)
133 return hsh_data ( (struct hsh_table *) h);
136 static inline void **
137 const_hsh_sort_copy (struct const_hsh_table *h)
139 return hsh_sort_copy ( (struct hsh_table *) h);
142 static inline void **
143 const_hsh_data_copy (struct const_hsh_table *h)
145 return hsh_data_copy ( (struct hsh_table *) h);
150 const_hsh_count (struct const_hsh_table *h)
152 return hsh_count ( (struct hsh_table *) h);
156 const_hsh_insert (struct const_hsh_table *h, const void *item)
158 return hsh_insert ( (struct hsh_table *) h, (void *) item);
162 const_hsh_replace (struct const_hsh_table *h, const void *item)
164 return hsh_replace ( (struct hsh_table *) h, (void *) item);
168 const_hsh_find (struct const_hsh_table *h, const void *item)
170 return hsh_find ( (struct hsh_table *) h, (void *) item);
174 const_hsh_delete (struct const_hsh_table *h, const void *item)
176 return hsh_delete ( (struct hsh_table *)h, (void *) item);
181 const_hsh_first (struct const_hsh_table *h, struct hsh_iterator *i)
183 return hsh_first ( (struct hsh_table *) h, i);
187 const_hsh_next (struct const_hsh_table *h, struct hsh_iterator *i)
189 return hsh_next ( (struct hsh_table *) h, i);