ISC DHCP 4.4.3-P1
A reference DHCPv4 and DHCPv6 implementation
 
Loading...
Searching...
No Matches
hash.h
Go to the documentation of this file.
1/* hash.h
2
3 Definitions for hashing... */
4
5/*
6 * Copyright (C) 2004-2022 Internet Systems Consortium, Inc. ("ISC")
7 * Copyright (c) 1995-2003 by Internet Software Consortium
8 *
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/.
12 *
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.
20 *
21 * Internet Systems Consortium, Inc.
22 * PO Box 360
23 * Newmarket, NH 03857 USA
24 * <info@isc.org>
25 * https://www.isc.org/
26 *
27 */
28
29#ifndef OMAPI_HASH_H
30#define OMAPI_HASH_H
31
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
39
40/* The purpose of the hashed_object_t struct is to not match anything else. */
41typedef struct {
42 int foo;
44
45typedef isc_result_t (*hash_foreach_func)(const void *, unsigned, void *);
47 const char *, int);
48typedef int (*hash_dereference) (hashed_object_t **, const char *, int);
49
52 const unsigned char *name;
53 unsigned len;
55};
56
57typedef int (*hash_comparator_t)(const void *, const void *, size_t);
58
59struct hash_table {
60 unsigned hash_count;
64 unsigned (*do_hash)(const void *, unsigned, unsigned);
65
66 /* This must remain the last entry in this table. */
67 struct hash_bucket *buckets [1];
68};
69
70struct named_hash {
72 const char *name;
74};
75
76#define HASH_FUNCTIONS_DECL(name, bufarg, type, hashtype) \
77void name##_hash_add (hashtype *, bufarg, unsigned, type *, \
78 const char *, int); \
79void name##_hash_delete (hashtype *, bufarg, unsigned, \
80 const char *, int); \
81int name##_hash_lookup (type **, hashtype *, bufarg, unsigned, \
82 const char *, int); \
83unsigned char * name##_hash_report(hashtype *); \
84int name##_hash_foreach (hashtype *, hash_foreach_func); \
85int name##_new_hash (hashtype **, unsigned, const char *, int); \
86void name##_free_hash_table (hashtype **, const char *, int);
87
88
89#define HASH_FUNCTIONS(name, bufarg, type, hashtype, ref, deref, hasher) \
90void name##_hash_add (hashtype *table, \
91 bufarg buf, unsigned len, type *ptr, \
92 const char *file, int line) \
93{ \
94 add_hash ((struct hash_table *)table, buf, \
95 len, (hashed_object_t *)ptr, file, line); \
96} \
97 \
98void name##_hash_delete (hashtype *table, bufarg buf, unsigned len, \
99 const char *file, int line) \
100{ \
101 delete_hash_entry ((struct hash_table *)table, buf, len, \
102 file, line); \
103} \
104 \
105int name##_hash_lookup (type **ptr, hashtype *table, \
106 bufarg buf, unsigned len, const char *file, int line) \
107{ \
108 return hash_lookup ((hashed_object_t **)ptr, \
109 (struct hash_table *)table, \
110 buf, len, file, line); \
111} \
112 \
113unsigned char * name##_hash_report(hashtype *table) \
114{ \
115 return hash_report((struct hash_table *)table); \
116} \
117 \
118int name##_hash_foreach (hashtype *table, hash_foreach_func func) \
119{ \
120 return hash_foreach ((struct hash_table *)table, \
121 func); \
122} \
123 \
124int name##_new_hash (hashtype **tp, unsigned c, const char *file, int line) \
125{ \
126 return new_hash ((struct hash_table **)tp, \
127 (hash_reference)ref, (hash_dereference)deref, c, \
128 hasher, file, line); \
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); \
134}
135
137int new_hash_table (struct hash_table **, unsigned, const char *, int);
138void free_hash_table (struct hash_table **, const char *, int);
139struct hash_bucket *new_hash_bucket (const char *, int);
140void free_hash_bucket (struct hash_bucket *, const char *, int);
141int new_hash(struct hash_table **,
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);
147unsigned do_id_hash(const void *, unsigned, unsigned);
148unsigned do_number_hash(const void *, unsigned, unsigned);
149unsigned do_ip4_hash(const void *, unsigned, unsigned);
150unsigned char *hash_report(struct hash_table *);
151void add_hash (struct hash_table *,
152 const void *, unsigned, hashed_object_t *,
153 const char *, int);
154void delete_hash_entry (struct hash_table *, const void *,
155 unsigned, const char *, int);
156int hash_lookup (hashed_object_t **, struct hash_table *,
157 const void *, unsigned, const char *, int);
159int casecmp (const void *s, const void *t, size_t len);
160
161#endif /* OMAPI_HASH_H */
struct hash_bucket * new_hash_bucket(const char *, int)
int casecmp(const void *s, const void *t, size_t len)
Definition hash.c:534
int hash_foreach(struct hash_table *, hash_foreach_func)
Definition hash.c:511
void free_hash_bucket(struct hash_bucket *, const char *, int)
Definition hash.c:193
unsigned do_case_hash(const void *, unsigned, unsigned)
Definition hash.c:240
void relinquish_hash_bucket_hunks(void)
unsigned do_id_hash(const void *, unsigned, unsigned)
Definition hash.c:290
void delete_hash_entry(struct hash_table *, const void *, unsigned, const char *, int)
Definition hash.c:432
int(* hash_dereference)(hashed_object_t **, const char *, int)
Definition hash.h:48
int(* hash_comparator_t)(const void *, const void *, size_t)
Definition hash.h:57
int hash_lookup(hashed_object_t **, struct hash_table *, const void *, unsigned, const char *, int)
Definition hash.c:474
isc_result_t(* hash_foreach_func)(const void *, unsigned, void *)
Definition hash.h:45
int new_hash(struct hash_table **, hash_reference, hash_dereference, unsigned, unsigned(*do_hash)(const void *, unsigned, unsigned), const char *, int)
Definition hash.c:212
int new_hash_table(struct hash_table **, unsigned, const char *, int)
Definition hash.c:55
int(* hash_reference)(hashed_object_t **, hashed_object_t *, const char *, int)
Definition hash.h:46
unsigned do_string_hash(const void *, unsigned, unsigned)
Definition hash.c:266
unsigned do_ip4_hash(const void *, unsigned, unsigned)
Definition hash.c:332
unsigned do_number_hash(const void *, unsigned, unsigned)
Definition hash.c:324
void add_hash(struct hash_table *, const void *, unsigned, hashed_object_t *, const char *, int)
Definition hash.c:396
void free_hash_table(struct hash_table **, const char *, int)
Definition hash.c:98
unsigned char * hash_report(struct hash_table *)
Definition hash.c:344
const char int
Definition omapip.h:442
unsigned len
Definition hash.h:53
struct hash_bucket * next
Definition hash.h:51
const unsigned char * name
Definition hash.h:52
hashed_object_t * value
Definition hash.h:54
hash_dereference dereferencer
Definition hash.h:62
unsigned(* do_hash)(const void *, unsigned, unsigned)
Definition hash.h:64
hash_comparator_t cmp
Definition hash.h:63
hash_reference referencer
Definition hash.h:61
struct hash_bucket * buckets[1]
Definition hash.h:67
unsigned hash_count
Definition hash.h:60
struct named_hash * next
Definition hash.h:71
struct hash_table * hash
Definition hash.h:73
const char * name
Definition hash.h:72