compat_ohash.h revision 371584c2eae4cf827fd406ba26c14f021adaaa70
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* $OpenBSD: ohash.h,v 1.2 2014/06/02 18:52:03 deraadt Exp $ */
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* Copyright (c) 1999, 2004 Marc Espie <espie@openbsd.org>
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Permission to use, copy, modify, and distribute this software for any
fa9e4066f08beec538e775443c5be79dd423fcabahrens * purpose with or without fee is hereby granted, provided that the above
fa9e4066f08beec538e775443c5be79dd423fcabahrens * copyright notice and this permission notice appear in all copies.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
fa9e4066f08beec538e775443c5be79dd423fcabahrens * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
fa9e4066f08beec538e775443c5be79dd423fcabahrens * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
fa9e4066f08beec538e775443c5be79dd423fcabahrens * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
fa9e4066f08beec538e775443c5be79dd423fcabahrens * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
fa9e4066f08beec538e775443c5be79dd423fcabahrens * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
fa9e4066f08beec538e775443c5be79dd423fcabahrens * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* Open hashing support.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Open hashing was chosen because it is much lighter than other hash
6b90ca488b504d3422b169269c3a86ccad80322clling * techniques, and more efficient in most cases.
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* user-visible data structure */
fa9e4066f08beec538e775443c5be79dd423fcabahrens void (*free)(void *, void *);
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* private structure. It's there just so you can do a sizeof */
fa9e4066f08beec538e775443c5be79dd423fcabahrens unsigned int size;
fa9e4066f08beec538e775443c5be79dd423fcabahrens unsigned int total;
fa9e4066f08beec538e775443c5be79dd423fcabahrens unsigned int deleted;
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* For this to be tweakable, we use small primitives, and leave part of the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * logic to the client application. e.g., hashing is left to the client
fa9e4066f08beec538e775443c5be79dd423fcabahrens * application. We also provide a simple table entry lookup that yields
fa9e4066f08beec538e775443c5be79dd423fcabahrens * a hashing table index (opaque) to be used in find/insert/remove.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The keys are stored at a known position in the client data.
fa9e4066f08beec538e775443c5be79dd423fcabahrensvoid ohash_init(struct ohash *, unsigned, struct ohash_info *);
fa9e4066f08beec538e775443c5be79dd423fcabahrensunsigned int ohash_lookup_interval(struct ohash *, const char *,
fa9e4066f08beec538e775443c5be79dd423fcabahrens const char *, uint32_t);
fa9e4066f08beec538e775443c5be79dd423fcabahrensunsigned int ohash_lookup_memory(struct ohash *, const char *,
fa9e4066f08beec538e775443c5be79dd423fcabahrensvoid *ohash_insert(struct ohash *, unsigned int, void *);
fa9e4066f08beec538e775443c5be79dd423fcabahrensvoid *ohash_create_entry(struct ohash_info *, const char *, const char **);
fa9e4066f08beec538e775443c5be79dd423fcabahrensunsigned int ohash_qlookupi(struct ohash *, const char *, const char **);
fa9e4066f08beec538e775443c5be79dd423fcabahrensunsigned int ohash_qlookup(struct ohash *, const char *);