3 Definitions for hashing... */
6 * Copyright (c) 1995-2001 Internet Software Consortium.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of The Internet Software Consortium nor the names
19 * of its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND
23 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR
27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
30 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
33 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * This software has been written for the Internet Software Consortium
37 * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc.
38 * To learn more about the Internet Software Consortium, see
39 * ``http://www.isc.org/''. To learn more about Vixie Enterprises,
40 * see ``http://www.vix.com''. To learn more about Nominum, Inc., see
41 * ``http://www.nominum.com''.
47 #define DEFAULT_HASH_SIZE 9973
49 /* The purpose of the hashed_object_t struct is to not match anything else. */
54 typedef void (*hash_foreach_func) (const unsigned char *,
55 unsigned, hashed_object_t *);
56 typedef int (*hash_reference) (hashed_object_t **, hashed_object_t *,
58 typedef int (*hash_dereference) (hashed_object_t **, const char *, int);
61 struct hash_bucket *next;
62 const unsigned char *name;
64 hashed_object_t *value;
67 typedef int (*hash_comparator_t)(const void *, const void *, unsigned long);
71 struct hash_bucket *buckets [DEFAULT_HASH_SIZE];
72 hash_reference referencer;
73 hash_dereference dereferencer;
74 hash_comparator_t cmp;
75 int (*do_hash) (const unsigned char *, unsigned, unsigned);
79 struct named_hash *next;
81 struct hash_table *hash;
84 #define HASH_FUNCTIONS_DECL(name, bufarg, type, hashtype) \
85 void name##_hash_add (hashtype *, bufarg, unsigned, type *, \
87 void name##_hash_delete (hashtype *, bufarg, unsigned, \
89 int name##_hash_lookup (type **, hashtype *, bufarg, unsigned, \
91 int name##_hash_foreach (hashtype *, \
92 void (*) (bufarg, unsigned, type *)); \
93 int name##_new_hash (hashtype **, int, const char *, int); \
94 void name##_free_hash_table (hashtype **, const char *, int);
97 #define HASH_FUNCTIONS(name, bufarg, type, hashtype, ref, deref) \
98 void name##_hash_add (hashtype *table, \
99 bufarg buf, unsigned len, type *ptr, \
100 const char *file, int line) \
102 add_hash ((struct hash_table *)table, \
103 (const unsigned char *)buf, \
104 len, (hashed_object_t *)ptr, file, line); \
107 void name##_hash_delete (hashtype *table, \
108 bufarg buf, unsigned len, const char *file, int line)\
110 delete_hash_entry ((struct hash_table *)table, \
111 (const unsigned char *)buf, \
115 int name##_hash_lookup (type **ptr, hashtype *table, \
116 bufarg buf, unsigned len, const char *file, int line) \
118 return hash_lookup ((hashed_object_t **)ptr, \
119 (struct hash_table *)table, \
120 (const unsigned char *)buf, len, file, line); \
123 int name##_hash_foreach (hashtype *table, \
124 void (*func) (bufarg, unsigned, type *)) \
126 return hash_foreach ((struct hash_table *)table, \
127 (hash_foreach_func)func); \
130 int name##_new_hash (hashtype **tp, int c, const char *file, int line) \
132 return new_hash ((struct hash_table **)tp, \
133 (hash_reference)ref, (hash_dereference)deref, c, \
137 void name##_free_hash_table (hashtype **table, const char *file, int line) \
139 free_hash_table ((struct hash_table **)table, file, line); \
142 void relinquish_hash_bucket_hunks (void);
143 int new_hash_table (struct hash_table **, int, const char *, int);
144 void free_hash_table (struct hash_table **, const char *, int);
145 struct hash_bucket *new_hash_bucket (const char *, int);
146 void free_hash_bucket (struct hash_bucket *, const char *, int);
147 int new_hash (struct hash_table **,
148 hash_reference, hash_dereference, int, const char *, int);
149 void add_hash (struct hash_table *,
150 const unsigned char *, unsigned, hashed_object_t *,
152 void delete_hash_entry (struct hash_table *, const unsigned char *,
153 unsigned, const char *, int);
154 int hash_lookup (hashed_object_t **, struct hash_table *,
155 const unsigned char *, unsigned, const char *, int);
156 int hash_foreach (struct hash_table *, hash_foreach_func);
157 int casecmp (const void *s, const void *t, unsigned long len);
159 #endif /* OMAPI_HASH_H */