Changed a lot of ints to bools.
[pspp-builds.git] / src / libpspp / hash.h
1 /* PSPP - computes sample statistics.
2    Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3    Written by Ben Pfaff <blp@gnu.org>.
4
5    This program is free software; you can redistribute it and/or
6    modify it under the terms of the GNU General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18    02110-1301, USA. */
19
20 #if !hash_h
21 #define hash_h 1
22
23 #include <stddef.h>
24 #include <stdbool.h>
25
26 typedef int hsh_compare_func (const void *, const void *, void *aux);
27 typedef unsigned hsh_hash_func (const void *, void *aux);
28 typedef void hsh_free_func (void *, void *aux);
29
30 /* Hash table iterator (opaque). */
31 struct hsh_iterator
32   {
33     size_t next;                /* Index of next entry. */
34   };
35
36 /* Hash functions. */
37 unsigned hsh_hash_bytes (const void *, size_t);
38 unsigned hsh_hash_string (const char *);
39 unsigned hsh_hash_case_string (const char *);
40 unsigned hsh_hash_int (int);
41 unsigned hsh_hash_double (double);
42
43 /* Hash tables. */
44 struct hsh_table *hsh_create (int m, hsh_compare_func *,
45                               hsh_hash_func *, hsh_free_func *,
46                               void *aux);
47 void hsh_clear (struct hsh_table *);
48 void hsh_destroy (struct hsh_table *);
49 void *const *hsh_sort (struct hsh_table *);
50 void *const *hsh_data (struct hsh_table *);
51 void **hsh_sort_copy (struct hsh_table *);
52 void **hsh_data_copy (struct hsh_table *);
53
54 /* Search and insertion. */
55 void **hsh_probe (struct hsh_table *, const void *);
56 void *hsh_insert (struct hsh_table *, void *);
57 void *hsh_replace (struct hsh_table *, void *);
58 void *hsh_find (struct hsh_table *, const void *);
59 bool hsh_delete (struct hsh_table *, const void *);
60
61 /* Iteration. */
62 void *hsh_first (struct hsh_table *, struct hsh_iterator *);
63 void *hsh_next (struct hsh_table *, struct hsh_iterator *);
64
65 /* Search and insertion with assertion. */
66 #if DEBUGGING
67 void hsh_force_insert (struct hsh_table *, void *);
68 void *hsh_force_find (struct hsh_table *, const void *);
69 void hsh_force_delete (struct hsh_table *, const void *);
70 #else
71 #define hsh_force_insert(A, B)  ((void) (*hsh_probe (A, B) = B))
72 #define hsh_force_find(A, B)    (hsh_find (A, B))
73 #define hsh_force_delete(A, B)  ((void) hsh_delete (A, B))
74 #endif
75
76 /* Number of entries in hash table H. */
77 size_t hsh_count (struct hsh_table *);
78
79 /* Debugging. */
80 #if DEBUGGING
81 void hsh_dump (struct hsh_table *);
82 #endif
83
84 #endif /* hash_h */