Blame


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