]> git.ipfire.org Git - thirdparty/dhcp.git/blame - includes/omapip/hash.h
copy rights update
[thirdparty/dhcp.git] / includes / omapip / hash.h
CommitLineData
d7837182
TL
1/* hash.h
2
3 Definitions for hashing... */
4
5/*
49a7fb58 6 * Copyright (C) 2004-2022 Internet Systems Consortium, Inc. ("ISC")
98311e4b 7 * Copyright (c) 1995-2003 by Internet Software Consortium
d7837182 8 *
7512d88b
TM
9 * This Source Code Form is subject to the terms of the Mozilla Public
10 * License, v. 2.0. If a copy of the MPL was not distributed with this
11 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
d7837182 12 *
98311e4b
DH
13 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
14 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
16 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
19 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
d7837182 20 *
98311e4b 21 * Internet Systems Consortium, Inc.
429a56d7
TM
22 * PO Box 360
23 * Newmarket, NH 03857 USA
98311e4b 24 * <info@isc.org>
2c85ac9b 25 * https://www.isc.org/
49733f31 26 *
d7837182
TL
27 */
28
c62871ba
DN
29#ifndef OMAPI_HASH_H
30#define OMAPI_HASH_H
31
f7fdb216
DH
32#if !defined (DEFAULT_HASH_SIZE)
33# define DEFAULT_HASH_SIZE 9973
34#endif
35
36#if !defined (KEY_HASH_SIZE)
37# define KEY_HASH_SIZE 1009
38#endif
d7837182 39
20916cae
TL
40/* The purpose of the hashed_object_t struct is to not match anything else. */
41typedef struct {
42 int foo;
43} hashed_object_t;
44
f7fdb216 45typedef isc_result_t (*hash_foreach_func)(const void *, unsigned, void *);
20916cae
TL
46typedef int (*hash_reference) (hashed_object_t **, hashed_object_t *,
47 const char *, int);
48typedef int (*hash_dereference) (hashed_object_t **, const char *, int);
287d577c 49
d7837182
TL
50struct hash_bucket {
51 struct hash_bucket *next;
b1b7b521
TL
52 const unsigned char *name;
53 unsigned len;
20916cae 54 hashed_object_t *value;
d7837182
TL
55};
56
d19e2cf7 57typedef int (*hash_comparator_t)(const void *, const void *, size_t);
e67f8322 58
d7837182 59struct hash_table {
b1b7b521 60 unsigned hash_count;
287d577c
TL
61 hash_reference referencer;
62 hash_dereference dereferencer;
e67f8322 63 hash_comparator_t cmp;
f7fdb216 64 unsigned (*do_hash)(const void *, unsigned, unsigned);
272ef1bc
SK
65
66 /* This must remain the last entry in this table. */
67 struct hash_bucket *buckets [1];
d7837182
TL
68};
69
ff404455
TL
70struct named_hash {
71 struct named_hash *next;
b1b7b521 72 const char *name;
ff404455
TL
73 struct hash_table *hash;
74};
20916cae 75
98311e4b
DH
76#define HASH_FUNCTIONS_DECL(name, bufarg, type, hashtype) \
77void name##_hash_add (hashtype *, bufarg, unsigned, type *, \
20916cae 78 const char *, int); \
98311e4b 79void name##_hash_delete (hashtype *, bufarg, unsigned, \
20916cae 80 const char *, int); \
98311e4b 81int name##_hash_lookup (type **, hashtype *, bufarg, unsigned, \
d0411fbd 82 const char *, int); \
6708d944 83unsigned char * name##_hash_report(hashtype *); \
06e77c34 84int name##_hash_foreach (hashtype *, hash_foreach_func); \
f7fdb216 85int name##_new_hash (hashtype **, unsigned, const char *, int); \
98311e4b 86void name##_free_hash_table (hashtype **, const char *, int);
d0411fbd 87
20916cae 88
f7fdb216 89#define HASH_FUNCTIONS(name, bufarg, type, hashtype, ref, deref, hasher) \
98311e4b 90void name##_hash_add (hashtype *table, \
20916cae
TL
91 bufarg buf, unsigned len, type *ptr, \
92 const char *file, int line) \
93{ \
f7fdb216 94 add_hash ((struct hash_table *)table, buf, \
20916cae
TL
95 len, (hashed_object_t *)ptr, file, line); \
96} \
97 \
f7fdb216
DH
98void name##_hash_delete (hashtype *table, bufarg buf, unsigned len, \
99 const char *file, int line) \
20916cae 100{ \
f7fdb216
DH
101 delete_hash_entry ((struct hash_table *)table, buf, len, \
102 file, line); \
20916cae
TL
103} \
104 \
98311e4b 105int name##_hash_lookup (type **ptr, hashtype *table, \
20916cae
TL
106 bufarg buf, unsigned len, const char *file, int line) \
107{ \
98311e4b
DH
108 return hash_lookup ((hashed_object_t **)ptr, \
109 (struct hash_table *)table, \
f7fdb216 110 buf, len, file, line); \
d0411fbd
TL
111} \
112 \
6708d944
DH
113unsigned char * name##_hash_report(hashtype *table) \
114{ \
115 return hash_report((struct hash_table *)table); \
116} \
117 \
06e77c34 118int name##_hash_foreach (hashtype *table, hash_foreach_func func) \
d0411fbd 119{ \
98311e4b 120 return hash_foreach ((struct hash_table *)table, \
06e77c34 121 func); \
98311e4b
DH
122} \
123 \
f7fdb216 124int name##_new_hash (hashtype **tp, unsigned c, const char *file, int line) \
98311e4b
DH
125{ \
126 return new_hash ((struct hash_table **)tp, \
127 (hash_reference)ref, (hash_dereference)deref, c, \
f7fdb216 128 hasher, file, line); \
98311e4b
DH
129} \
130 \
131void name##_free_hash_table (hashtype **table, const char *file, int line) \
132{ \
133 free_hash_table ((struct hash_table **)table, file, line); \
20916cae
TL
134}
135
d758ad8c 136void relinquish_hash_bucket_hunks (void);
f7fdb216 137int new_hash_table (struct hash_table **, unsigned, const char *, int);
98311e4b 138void free_hash_table (struct hash_table **, const char *, int);
c62871ba
DN
139struct hash_bucket *new_hash_bucket (const char *, int);
140void free_hash_bucket (struct hash_bucket *, const char *, int);
f7fdb216
DH
141int new_hash(struct hash_table **,
142 hash_reference, hash_dereference, unsigned,
143 unsigned (*do_hash)(const void *, unsigned, unsigned),
144 const char *, int);
145unsigned do_string_hash(const void *, unsigned, unsigned);
146unsigned do_case_hash(const void *, unsigned, unsigned);
6708d944 147unsigned do_id_hash(const void *, unsigned, unsigned);
f7fdb216
DH
148unsigned do_number_hash(const void *, unsigned, unsigned);
149unsigned do_ip4_hash(const void *, unsigned, unsigned);
6708d944 150unsigned char *hash_report(struct hash_table *);
c62871ba 151void add_hash (struct hash_table *,
f7fdb216 152 const void *, unsigned, hashed_object_t *,
c62871ba 153 const char *, int);
f7fdb216 154void delete_hash_entry (struct hash_table *, const void *,
c62871ba
DN
155 unsigned, const char *, int);
156int hash_lookup (hashed_object_t **, struct hash_table *,
f7fdb216 157 const void *, unsigned, const char *, int);
c62871ba 158int hash_foreach (struct hash_table *, hash_foreach_func);
d19e2cf7 159int casecmp (const void *s, const void *t, size_t len);
c62871ba
DN
160
161#endif /* OMAPI_HASH_H */