Fixed bug reporting the significance of paired value t-test.
[pspp-builds.git] / src / libpspp / hash.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3
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.
8
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.
13
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/>. */
16
17 #if !hash_h
18 #define hash_h 1
19
20 #include <stddef.h>
21 #include <stdbool.h>
22
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);
26
27 /* Hash table iterator (opaque). */
28 struct hsh_iterator
29   {
30     size_t next;                /* Index of next entry. */
31   };
32
33 /* Hash functions. */
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);
39
40 /* Hash tables. */
41 struct hsh_table *hsh_create (int m, hsh_compare_func *,
42                               hsh_hash_func *, hsh_free_func *,
43                               const void *aux);
44
45 struct pool;
46 struct hsh_table *hsh_create_pool (struct pool *pool, int m,
47                                    hsh_compare_func *,
48                                    hsh_hash_func *, hsh_free_func *,
49                                    const void *aux);
50
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 *);
57
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 *);
64
65 /* Iteration. */
66 void *hsh_first (struct hsh_table *, struct hsh_iterator *);
67 void *hsh_next (struct hsh_table *, struct hsh_iterator *);
68
69 /* Search and insertion with assertion. */
70 #if DEBUGGING
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 *);
74 #else
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))
78 #endif
79
80 /* Number of entries in hash table H. */
81 size_t hsh_count (struct hsh_table *);
82
83 /* Debugging. */
84 #if DEBUGGING
85 void hsh_dump (struct hsh_table *);
86 #endif
87
88
89 /* Const Wrappers for the above */
90
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,
95                   const void *aux)
96 {
97   return (struct const_hsh_table *) hsh_create (m, hcf, hhf, hff, aux);
98 }
99
100
101
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,
106                        const void *aux)
107 {
108   return (struct const_hsh_table *) hsh_create_pool (pool, m, cf, hf, ff, aux);
109 }
110
111
112 static inline void
113 const_hsh_clear (struct const_hsh_table *h)
114 {
115   hsh_clear ( (struct hsh_table *) h);
116 }
117
118 static inline void
119 const_hsh_destroy (struct const_hsh_table *h)
120 {
121   hsh_destroy ( (struct hsh_table *) h);
122 }
123
124 static inline void *const *
125 const_hsh_sort (struct const_hsh_table *h)
126 {
127   return hsh_sort ( (struct hsh_table *) h);
128 }
129
130 static inline void *const *
131 const_hsh_data (struct const_hsh_table *h)
132 {
133   return hsh_data ( (struct hsh_table *) h);
134 }
135
136 static inline void **
137 const_hsh_sort_copy (struct const_hsh_table *h)
138 {
139   return hsh_sort_copy ( (struct hsh_table *) h);
140 }
141
142 static inline void **
143 const_hsh_data_copy (struct const_hsh_table *h)
144 {
145   return hsh_data_copy ( (struct hsh_table *) h);
146 }
147
148
149 static inline size_t
150 const_hsh_count (struct const_hsh_table *h)
151 {
152   return hsh_count ( (struct hsh_table *) h);
153 }
154
155 static inline void *
156 const_hsh_insert (struct const_hsh_table *h, const void *item)
157 {
158   return hsh_insert ( (struct hsh_table *) h, (void *) item);
159 }
160
161 static inline void *
162 const_hsh_replace (struct const_hsh_table *h, const void *item)
163 {
164   return hsh_replace ( (struct hsh_table *) h, (void *) item);
165 }
166
167 static inline void *
168 const_hsh_find (struct const_hsh_table *h, const void *item)
169 {
170   return hsh_find ( (struct hsh_table *) h, (void *) item);
171 }
172
173 static inline bool
174 const_hsh_delete (struct const_hsh_table *h, const void *item)
175 {
176   return hsh_delete ( (struct hsh_table *)h, (void *) item);
177 }
178
179
180 static inline void *
181 const_hsh_first (struct const_hsh_table *h, struct hsh_iterator *i)
182 {
183   return hsh_first ( (struct hsh_table *) h, i);
184 }
185
186 static inline void *
187 const_hsh_next (struct const_hsh_table *h, struct hsh_iterator *i)
188 {
189   return hsh_next ( (struct hsh_table *) h, i);
190 }
191
192
193 #endif /* hash_h */