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