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

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

1.1       espie       1: #ifndef OHASH_H
                      2: #define OHASH_H
1.11    ! espie       3: /* $OpenBSD: ohash.h,v 1.10 2012/09/23 15:05:23 espie Exp $ */
1.1       espie       4: /* ex:ts=8 sw=4:
                      5:  */
                      6:
1.7       espie       7: /* Copyright (c) 1999, 2004 Marc Espie <espie@openbsd.org>
1.1       espie       8:  *
1.7       espie       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.
1.1       espie      12:  *
1.7       espie      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.
1.1       espie      20:  */
                     21:
                     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.
                     25:  */
                     26:
1.11    ! espie      27: /* user-visible data structure */
1.1       espie      28: struct ohash_info {
                     29:        ptrdiff_t key_offset;
                     30:        void *data;     /* user data */
1.11    ! espie      31:        void *(*calloc)(size_t, size_t, void *);
        !            32:        void (*free)(void *, void *);
1.2       millert    33:        void *(*alloc)(size_t, void *);
1.1       espie      34: };
                     35:
                     36: struct _ohash_record;
                     37:
1.11    ! espie      38: /* private structure. It's there just so you can do a sizeof */
1.1       espie      39: struct 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
1.2       millert    54: void ohash_init(struct ohash *, unsigned, struct ohash_info *);
                     55: void ohash_delete(struct ohash *);
1.1       espie      56:
1.3       millert    57: unsigned int ohash_lookup_interval(struct ohash *, const char *,
1.9       espie      58:            const char *, uint32_t);
1.3       millert    59: unsigned int ohash_lookup_memory(struct ohash *, const char *,
1.9       espie      60:            size_t, uint32_t)
1.6       avsm       61:                __attribute__ ((__bounded__(__string__,2,3)));
1.2       millert    62: void *ohash_find(struct ohash *, unsigned int);
                     63: void *ohash_remove(struct ohash *, unsigned int);
                     64: void *ohash_insert(struct ohash *, unsigned int, void *);
                     65: void *ohash_first(struct ohash *, unsigned int *);
                     66: void *ohash_next(struct ohash *, unsigned int *);
                     67: unsigned int ohash_entries(struct ohash *);
1.1       espie      68:
1.2       millert    69: void *ohash_create_entry(struct ohash_info *, const char *, const char **);
1.10      espie      70: uint32_t ohash_interval(const char *, const char **);
1.1       espie      71:
1.2       millert    72: unsigned int ohash_qlookupi(struct ohash *, const char *, const char **);
                     73: unsigned int ohash_qlookup(struct ohash *, const char *);
1.1       espie      74: __END_DECLS
                     75: #endif