Blame


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