Blame


1 b4252034 2021-07-22 op /* $OpenBSD: ohash.h,v 1.2 2014/06/02 18:52:03 deraadt Exp $ */
2 b4252034 2021-07-22 op
3 b4252034 2021-07-22 op /* Copyright (c) 1999, 2004 Marc Espie <espie@openbsd.org>
4 b4252034 2021-07-22 op *
5 b4252034 2021-07-22 op * Permission to use, copy, modify, and distribute this software for any
6 b4252034 2021-07-22 op * purpose with or without fee is hereby granted, provided that the above
7 b4252034 2021-07-22 op * copyright notice and this permission notice appear in all copies.
8 b4252034 2021-07-22 op *
9 b4252034 2021-07-22 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 b4252034 2021-07-22 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 b4252034 2021-07-22 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 b4252034 2021-07-22 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 b4252034 2021-07-22 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 b4252034 2021-07-22 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 b4252034 2021-07-22 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 b4252034 2021-07-22 op */
17 b4252034 2021-07-22 op
18 b4252034 2021-07-22 op #ifndef OHASH_H
19 b4252034 2021-07-22 op #define OHASH_H
20 b4252034 2021-07-22 op
21 b4252034 2021-07-22 op /* Open hashing support.
22 b4252034 2021-07-22 op * Open hashing was chosen because it is much lighter than other hash
23 b4252034 2021-07-22 op * techniques, and more efficient in most cases.
24 b4252034 2021-07-22 op */
25 b4252034 2021-07-22 op
26 b4252034 2021-07-22 op /* user-visible data structure */
27 b4252034 2021-07-22 op struct ohash_info {
28 b4252034 2021-07-22 op ptrdiff_t key_offset;
29 b4252034 2021-07-22 op void *data; /* user data */
30 b4252034 2021-07-22 op void *(*calloc)(size_t, size_t, void *);
31 b4252034 2021-07-22 op void (*free)(void *, void *);
32 b4252034 2021-07-22 op void *(*alloc)(size_t, void *);
33 b4252034 2021-07-22 op };
34 b4252034 2021-07-22 op
35 b4252034 2021-07-22 op struct _ohash_record;
36 b4252034 2021-07-22 op
37 b4252034 2021-07-22 op /* private structure. It's there just so you can do a sizeof */
38 b4252034 2021-07-22 op struct ohash {
39 b4252034 2021-07-22 op struct _ohash_record *t;
40 b4252034 2021-07-22 op struct ohash_info info;
41 b4252034 2021-07-22 op unsigned int size;
42 b4252034 2021-07-22 op unsigned int total;
43 b4252034 2021-07-22 op unsigned int deleted;
44 b4252034 2021-07-22 op };
45 b4252034 2021-07-22 op
46 b4252034 2021-07-22 op /* For this to be tweakable, we use small primitives, and leave part of the
47 b4252034 2021-07-22 op * logic to the client application. e.g., hashing is left to the client
48 b4252034 2021-07-22 op * application. We also provide a simple table entry lookup that yields
49 b4252034 2021-07-22 op * a hashing table index (opaque) to be used in find/insert/remove.
50 b4252034 2021-07-22 op * The keys are stored at a known position in the client data.
51 b4252034 2021-07-22 op */
52 b4252034 2021-07-22 op void ohash_init(struct ohash *, unsigned, struct ohash_info *);
53 b4252034 2021-07-22 op void ohash_delete(struct ohash *);
54 b4252034 2021-07-22 op
55 b4252034 2021-07-22 op unsigned int ohash_lookup_interval(struct ohash *, const char *,
56 b4252034 2021-07-22 op const char *, uint32_t);
57 b4252034 2021-07-22 op unsigned int ohash_lookup_memory(struct ohash *, const char *,
58 b4252034 2021-07-22 op size_t, uint32_t);
59 b4252034 2021-07-22 op void *ohash_find(struct ohash *, unsigned int);
60 b4252034 2021-07-22 op void *ohash_remove(struct ohash *, unsigned int);
61 b4252034 2021-07-22 op void *ohash_insert(struct ohash *, unsigned int, void *);
62 b4252034 2021-07-22 op void *ohash_first(struct ohash *, unsigned int *);
63 b4252034 2021-07-22 op void *ohash_next(struct ohash *, unsigned int *);
64 b4252034 2021-07-22 op unsigned int ohash_entries(struct ohash *);
65 b4252034 2021-07-22 op
66 b4252034 2021-07-22 op void *ohash_create_entry(struct ohash_info *, const char *, const char **);
67 b4252034 2021-07-22 op uint32_t ohash_interval(const char *, const char **);
68 b4252034 2021-07-22 op
69 b4252034 2021-07-22 op unsigned int ohash_qlookupi(struct ohash *, const char *, const char **);
70 b4252034 2021-07-22 op unsigned int ohash_qlookup(struct ohash *, const char *);
71 b4252034 2021-07-22 op #endif