Annotation of src/include/ohash.h, Revision 1.1
1.1 ! espie 1: #ifndef OHASH_H
! 2: #define OHASH_H
! 3: /* $OpenBSD: ohash.h,v 1.2 2000/06/28 10:12:49 espie Exp $ */
! 4: /* ex:ts=8 sw=4:
! 5: */
! 6:
! 7: /*
! 8: * Copyright (c) 1999 Marc Espie.
! 9: *
! 10: * Code written for the OpenBSD project.
! 11: *
! 12: * Redistribution and use in source and binary forms, with or without
! 13: * modification, are permitted provided that the following conditions
! 14: * are met:
! 15: * 1. Redistributions of source code must retain the above copyright
! 16: * notice, this list of conditions and the following disclaimer.
! 17: * 2. Redistributions in binary form must reproduce the above copyright
! 18: * notice, this list of conditions and the following disclaimer in the
! 19: * documentation and/or other materials provided with the distribution.
! 20: *
! 21: * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS
! 22: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
! 23: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
! 24: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD
! 25: * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
! 26: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
! 27: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
! 28: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
! 29: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
! 30: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
! 31: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
! 32: */
! 33:
! 34: /* Open hashing support.
! 35: * Open hashing was chosen because it is much lighter than other hash
! 36: * techniques, and more efficient in most cases.
! 37: */
! 38:
! 39: struct ohash_info {
! 40: ptrdiff_t key_offset;
! 41: void *data; /* user data */
! 42: void *(*halloc) __P((size_t, void *));
! 43: void (*hfree) __P((void *, size_t, void *));
! 44: void *(*alloc) __P((size_t, void *));
! 45: };
! 46:
! 47: struct _ohash_record;
! 48:
! 49: struct ohash {
! 50: struct _ohash_record *t;
! 51: struct ohash_info info;
! 52: unsigned int size;
! 53: unsigned int total;
! 54: unsigned int deleted;
! 55: };
! 56:
! 57: /* For this to be tweakable, we use small primitives, and leave part of the
! 58: * logic to the client application. e.g., hashing is left to the client
! 59: * application. We also provide a simple table entry lookup that yields
! 60: * a hashing table index (opaque) to be used in find/insert/remove.
! 61: * The keys are stored at a known position in the client data.
! 62: */
! 63: __BEGIN_DECLS
! 64: void ohash_init __P((struct ohash *, unsigned, struct ohash_info *));
! 65: void ohash_delete __P((struct ohash *));
! 66:
! 67: unsigned int ohash_lookup_string __P((struct ohash *, const char *, u_int32_t));
! 68: unsigned int ohash_lookup_interval __P((struct ohash *, const char *, \
! 69: const char *, u_int32_t));
! 70: unsigned int ohash_lookup_memory __P((struct ohash *, const char *, \
! 71: size_t, u_int32_t));
! 72: void *ohash_find __P((struct ohash *, unsigned int));
! 73: void *ohash_remove __P((struct ohash *, unsigned int));
! 74: void *ohash_insert __P((struct ohash *, unsigned int, void *));
! 75: void *ohash_first __P((struct ohash *, unsigned int *));
! 76: void *ohash_next __P((struct ohash *, unsigned int *));
! 77: unsigned int ohash_entries __P((struct ohash *));
! 78:
! 79: void *ohash_create_entry __P((struct ohash_info *, const char *, const char **));
! 80: u_int32_t ohash_interval __P((const char *, const char **));
! 81:
! 82: unsigned int ohash_qlookupi __P((struct ohash *, const char *, const char **));
! 83: unsigned int ohash_qlookup __P((struct ohash *, const char *));
! 84: __END_DECLS
! 85: #endif