1#ifndef OHASH_H 2#define OHASH_H 3/* $OpenBSD: ohash.h,v 1.8 2005/12/29 18:54:47 jaredy Exp $ */ 4/* ex:ts=8 sw=4: 5 */ 6 7/* Copyright (c) 1999, 2004 Marc Espie <espie@openbsd.org> 8 * 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. 12 * 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. 20 * 21 * $FreeBSD: releng/10.3/usr.bin/m4/lib/ohash.h 228063 2011-11-28 13:32:39Z bapt $ 22 */ 23 24/* Open hashing support. 25 * Open hashing was chosen because it is much lighter than other hash 26 * techniques, and more efficient in most cases. 27 */ 28 29struct ohash_info { 30 ptrdiff_t key_offset; 31 void *data; /* user data */ 32 void *(*halloc)(size_t, void *); 33 void (*hfree)(void *, size_t, void *); 34 void *(*alloc)(size_t, void *); 35}; 36 37struct _ohash_record; 38 39struct ohash { 40 struct _ohash_record *t; 41 struct ohash_info info; 42 unsigned int size; 43 unsigned int total; 44 unsigned int deleted; 45}; 46 47/* For this to be tweakable, we use small primitives, and leave part of the 48 * logic to the client application. e.g., hashing is left to the client 49 * application. We also provide a simple table entry lookup that yields 50 * a hashing table index (opaque) to be used in find/insert/remove. 51 * The keys are stored at a known position in the client data. 52 */ 53__BEGIN_DECLS 54void ohash_init(struct ohash *, unsigned, struct ohash_info *); 55void ohash_delete(struct ohash *); 56 57unsigned int ohash_lookup_interval(struct ohash *, const char *, 58 const char *, u_int32_t); 59unsigned int ohash_lookup_memory(struct ohash *, const char *, 60 size_t, u_int32_t); 61void *ohash_find(struct ohash *, unsigned int); 62void *ohash_remove(struct ohash *, unsigned int); 63void *ohash_insert(struct ohash *, unsigned int, void *); 64void *ohash_first(struct ohash *, unsigned int *); 65void *ohash_next(struct ohash *, unsigned int *); 66unsigned int ohash_entries(struct ohash *); 67 68void *ohash_create_entry(struct ohash_info *, const char *, const char **); 69u_int32_t ohash_interval(const char *, const char **); 70 71unsigned int ohash_qlookupi(struct ohash *, const char *, const char **); 72unsigned int ohash_qlookup(struct ohash *, const char *); 73__END_DECLS 74#endif 75 76