etc/services - sync with NetBSD-8
[minix.git] / external / bsd / mdocml / dist / compat_ohash.h
blob9099adc51f5562ca8e4fe4f913a5fe4ebc31fc33
1 #ifndef OHASH_H
2 #define OHASH_H
3 /* $OpenBSD: ohash.h,v 1.9 2006/01/16 15:52:25 espie Exp $ */
4 /* ex:ts=8 sw=4:
5 */
7 /* Copyright (c) 1999, 2004 Marc Espie <espie@openbsd.org>
9 * Permission to use, copy, modify, and distribute this software for any
10 * purpose with or without fee is hereby granted, provided that the above
11 * copyright notice and this permission notice appear in all copies.
13 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 /* Open hashing support.
23 * Open hashing was chosen because it is much lighter than other hash
24 * techniques, and more efficient in most cases.
27 struct ohash_info {
28 ptrdiff_t key_offset;
29 void *data; /* user data */
30 void *(*halloc)(size_t, void *);
31 void (*hfree)(void *, size_t, void *);
32 void *(*alloc)(size_t, void *);
35 struct _ohash_record;
37 struct ohash {
38 struct _ohash_record *t;
39 struct ohash_info info;
40 unsigned int size;
41 unsigned int total;
42 unsigned int deleted;
45 /* For this to be tweakable, we use small primitives, and leave part of the
46 * logic to the client application. e.g., hashing is left to the client
47 * application. We also provide a simple table entry lookup that yields
48 * a hashing table index (opaque) to be used in find/insert/remove.
49 * The keys are stored at a known position in the client data.
51 __BEGIN_DECLS
52 void ohash_init(struct ohash *, unsigned, struct ohash_info *);
53 void ohash_delete(struct ohash *);
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 *,
58 size_t, uint32_t)
59 __attribute__ ((__bounded__(__string__,2,3)));
60 void *ohash_find(struct ohash *, unsigned int);
61 void *ohash_remove(struct ohash *, unsigned int);
62 void *ohash_insert(struct ohash *, unsigned int, void *);
63 void *ohash_first(struct ohash *, unsigned int *);
64 void *ohash_next(struct ohash *, unsigned int *);
65 unsigned int ohash_entries(struct ohash *);
67 void *ohash_create_entry(struct ohash_info *, const char *, const char **);
68 uint32_t ohash_interval(const char *, const char **);
70 unsigned int ohash_qlookupi(struct ohash *, const char *, const char **);
71 unsigned int ohash_qlookup(struct ohash *, const char *);
72 __END_DECLS
73 #endif