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/>. */
22 #include <libpspp/hash-functions.h>
24 typedef int hsh_compare_func (const void *, const void *, const void *aux);
25 typedef unsigned hsh_hash_func (const void *, const void *aux);
26 typedef void hsh_free_func (void *, const void *aux);
28 /* Hash table iterator (opaque). */
31 size_t next; /* Index of next entry. */
35 struct hsh_table *hsh_create (int m, hsh_compare_func *,
36 hsh_hash_func *, hsh_free_func *,
40 struct hsh_table *hsh_create_pool (struct pool *pool, int m,
42 hsh_hash_func *, hsh_free_func *,
45 void hsh_clear (struct hsh_table *);
46 void hsh_destroy (struct hsh_table *);
47 void *const *hsh_sort (struct hsh_table *);
48 void *const *hsh_data (struct hsh_table *);
49 void **hsh_sort_copy (struct hsh_table *);
50 void **hsh_data_copy (struct hsh_table *);
52 /* Search and insertion. */
53 void **hsh_probe (struct hsh_table *, const void *);
54 void *hsh_insert (struct hsh_table *, void *);
55 void *hsh_replace (struct hsh_table *, void *);
56 void *hsh_find (struct hsh_table *, const void *);
57 bool hsh_delete (struct hsh_table *, const void *);
60 void *hsh_first (struct hsh_table *, struct hsh_iterator *);
61 void *hsh_next (struct hsh_table *, struct hsh_iterator *);
63 /* Search and insertion with assertion. */
65 void hsh_force_insert (struct hsh_table *, void *);
66 void *hsh_force_find (struct hsh_table *, const void *);
67 void hsh_force_delete (struct hsh_table *, const void *);
69 #define hsh_force_insert(A, B) ((void) (*hsh_probe (A, B) = B))
70 #define hsh_force_find(A, B) (hsh_find (A, B))
71 #define hsh_force_delete(A, B) ((void) hsh_delete (A, B))
74 /* Number of entries in hash table H. */
75 size_t hsh_count (struct hsh_table *);
79 void hsh_dump (struct hsh_table *);
83 /* Const Wrappers for the above */
85 static inline struct const_hsh_table *
86 const_hsh_create (int m,
87 hsh_compare_func *hcf,
88 hsh_hash_func *hhf, hsh_free_func *hff,
91 return (struct const_hsh_table *) hsh_create (m, hcf, hhf, hff, aux);
96 static inline struct const_hsh_table *
97 const_hsh_create_pool (struct pool *pool, int m,
99 hsh_hash_func *hf, hsh_free_func *ff,
102 return (struct const_hsh_table *) hsh_create_pool (pool, m, cf, hf, ff, aux);
107 const_hsh_clear (struct const_hsh_table *h)
109 hsh_clear ( (struct hsh_table *) h);
113 const_hsh_destroy (struct const_hsh_table *h)
115 hsh_destroy ( (struct hsh_table *) h);
118 static inline void *const *
119 const_hsh_sort (struct const_hsh_table *h)
121 return hsh_sort ( (struct hsh_table *) h);
124 static inline void *const *
125 const_hsh_data (struct const_hsh_table *h)
127 return hsh_data ( (struct hsh_table *) h);
130 static inline void **
131 const_hsh_sort_copy (struct const_hsh_table *h)
133 return hsh_sort_copy ( (struct hsh_table *) h);
136 static inline void **
137 const_hsh_data_copy (struct const_hsh_table *h)
139 return hsh_data_copy ( (struct hsh_table *) h);
144 const_hsh_count (struct const_hsh_table *h)
146 return hsh_count ( (struct hsh_table *) h);
150 const_hsh_insert (struct const_hsh_table *h, const void *item)
152 return hsh_insert ( (struct hsh_table *) h, (void *) item);
156 const_hsh_replace (struct const_hsh_table *h, const void *item)
158 return hsh_replace ( (struct hsh_table *) h, (void *) item);
162 const_hsh_find (struct const_hsh_table *h, const void *item)
164 return hsh_find ( (struct hsh_table *) h, (void *) item);
168 const_hsh_delete (struct const_hsh_table *h, const void *item)
170 return hsh_delete ( (struct hsh_table *)h, (void *) item);
175 const_hsh_first (struct const_hsh_table *h, struct hsh_iterator *i)
177 return hsh_first ( (struct hsh_table *) h, i);
181 const_hsh_next (struct const_hsh_table *h, struct hsh_iterator *i)
183 return hsh_next ( (struct hsh_table *) h, i);