Blame


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