1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3 Written by Ben Pfaff <blp@gnu.org>.
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA
23 /* Hash table (opaque). */
26 int n; /* Number of filled entries. */
27 int m; /* Number of entries. */
28 int *mp; /* Pointer into hsh_prime_tab[]. */
29 void **table; /* Hash table proper. */
32 int (*compare) (const void *, const void *, void *param);
33 unsigned (*hash) (const void *, void *param);
34 void (*free) (void *, void *param);
37 /* Hash table iterator (opaque). */
40 int init; /* Initialized? */
41 int next; /* Index of next entry. */
44 #define hsh_iterator_init(ITERATOR) (ITERATOR).init = 0
46 /* Prime numbers and hash functions. */
47 int *hsh_next_prime (int) __attribute__ ((const));
48 int hashpjw_d (const char *s1, const char *s2);
50 #if __GNUC__>=2 && __OPTIMIZE__
52 hashpjw (const char *s)
54 return hashpjw_d (s, &s[strlen (s)]);
57 int hashpjw (const char *s);
61 struct hsh_table *hsh_create (int m,
62 int (*compare) (const void *, const void *,
64 unsigned (*hash) (const void *, void *param),
65 void (*free) (void *, void *param),
67 void hsh_clear (struct hsh_table *);
68 void hsh_destroy (struct hsh_table *);
69 void hsh_rehash (struct hsh_table *);
70 void **hsh_sort (struct hsh_table *,
71 int (*compare) (const void *, const void *, void *param));
73 void hsh_dump (struct hsh_table *);
77 void **hsh_probe (struct hsh_table *, const void *);
78 void *hsh_find (struct hsh_table *, const void *);
79 void *hsh_foreach (struct hsh_table *, struct hsh_iterator *);
82 void force_hsh_insert (struct hsh_table *, void *);
83 void *force_hsh_find (struct hsh_table *, const void *);
85 #define force_hsh_insert(A, B) \
86 do *hsh_probe (A, B) = B; while (0)
87 #define force_hsh_find(A, B) \
91 /* Returns number of used elements in hash table H. */
92 #define hsh_count(H) \