[BACK]Return to ohash.h CVS log [TXT][DIR] Up to [local] / src / include

Annotation of src/include/ohash.h, Revision 1.6

1.1       espie       1: #ifndef OHASH_H
                      2: #define OHASH_H
1.6     ! avsm        3: /* $OpenBSD: ohash.h,v 1.5 2003/06/26 19:34:17 avsm Exp $ */
1.1       espie       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 */
1.2       millert    42:        void *(*halloc)(size_t, void *);
                     43:        void (*hfree)(void *, size_t, void *);
                     44:        void *(*alloc)(size_t, void *);
1.1       espie      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
1.2       millert    64: void ohash_init(struct ohash *, unsigned, struct ohash_info *);
                     65: void ohash_delete(struct ohash *);
1.1       espie      66:
1.2       millert    67: unsigned int ohash_lookup_string(struct ohash *, const char *, u_int32_t);
1.3       millert    68: unsigned int ohash_lookup_interval(struct ohash *, const char *,
                     69:            const char *, u_int32_t);
                     70: unsigned int ohash_lookup_memory(struct ohash *, const char *,
1.6     ! avsm       71:            size_t, u_int32_t)
        !            72:                __attribute__ ((__bounded__(__string__,2,3)));
1.2       millert    73: void *ohash_find(struct ohash *, unsigned int);
                     74: void *ohash_remove(struct ohash *, unsigned int);
                     75: void *ohash_insert(struct ohash *, unsigned int, void *);
                     76: void *ohash_first(struct ohash *, unsigned int *);
                     77: void *ohash_next(struct ohash *, unsigned int *);
                     78: unsigned int ohash_entries(struct ohash *);
1.1       espie      79:
1.2       millert    80: void *ohash_create_entry(struct ohash_info *, const char *, const char **);
                     81: u_int32_t ohash_interval(const char *, const char **);
1.1       espie      82:
1.2       millert    83: unsigned int ohash_qlookupi(struct ohash *, const char *, const char **);
                     84: unsigned int ohash_qlookup(struct ohash *, const char *);
1.1       espie      85: __END_DECLS
                     86: #endif