Annotation of embedaddon/mpd/src/contrib/libpdel/util/ghash.h, revision 1.1

1.1     ! misho       1: 
        !             2: /*
        !             3:  * Copyright (c) 2001-2002 Packet Design, LLC.
        !             4:  * All rights reserved.
        !             5:  * 
        !             6:  * Subject to the following obligations and disclaimer of warranty,
        !             7:  * use and redistribution of this software, in source or object code
        !             8:  * forms, with or without modifications are expressly permitted by
        !             9:  * Packet Design; provided, however, that:
        !            10:  * 
        !            11:  *    (i)  Any and all reproductions of the source or object code
        !            12:  *         must include the copyright notice above and the following
        !            13:  *         disclaimer of warranties; and
        !            14:  *    (ii) No rights are granted, in any manner or form, to use
        !            15:  *         Packet Design trademarks, including the mark "PACKET DESIGN"
        !            16:  *         on advertising, endorsements, or otherwise except as such
        !            17:  *         appears in the above copyright notice or in the software.
        !            18:  * 
        !            19:  * THIS SOFTWARE IS BEING PROVIDED BY PACKET DESIGN "AS IS", AND
        !            20:  * TO THE MAXIMUM EXTENT PERMITTED BY LAW, PACKET DESIGN MAKES NO
        !            21:  * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING
        !            22:  * THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED
        !            23:  * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
        !            24:  * OR NON-INFRINGEMENT.  PACKET DESIGN DOES NOT WARRANT, GUARANTEE,
        !            25:  * OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS
        !            26:  * OF THE USE OF THIS SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY,
        !            27:  * RELIABILITY OR OTHERWISE.  IN NO EVENT SHALL PACKET DESIGN BE
        !            28:  * LIABLE FOR ANY DAMAGES RESULTING FROM OR ARISING OUT OF ANY USE
        !            29:  * OF THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY DIRECT,
        !            30:  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE, OR CONSEQUENTIAL
        !            31:  * DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF
        !            32:  * USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY THEORY OF
        !            33:  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
        !            34:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
        !            35:  * THE USE OF THIS SOFTWARE, EVEN IF PACKET DESIGN IS ADVISED OF
        !            36:  * THE POSSIBILITY OF SUCH DAMAGE.
        !            37:  *
        !            38:  * Author: Archie Cobbs <archie@freebsd.org>
        !            39:  */
        !            40: 
        !            41: #ifndef _PDEL_UTIL_GHASH_H_
        !            42: #define _PDEL_UTIL_GHASH_H_
        !            43: 
        !            44: /*
        !            45:  * General purpose hash table stuff.
        !            46:  */
        !            47: 
        !            48: /**********************************************************************
        !            49:                        HASH TABLE FUNCTION TYPES
        !            50: **********************************************************************/
        !            51: 
        !            52: struct ghash;
        !            53: struct ghash_walk;
        !            54: 
        !            55: /*
        !            56:  * How to compare two items for equality.
        !            57:  *
        !            58:  * If this function is not specified, then "item1 == item2" is used.
        !            59:  */
        !            60: typedef int    ghash_equal_t(struct ghash *g,
        !            61:                        const void *item1, const void *item2);
        !            62: 
        !            63: /*
        !            64:  * How to compute the hash value for an item.
        !            65:  *
        !            66:  * If this function is not specified, then "(u_int32_t)item" is used.
        !            67:  */
        !            68: typedef u_int32_t ghash_hash_t(struct ghash *g, const void *item);
        !            69: 
        !            70: /*
        !            71:  * Notification that an item is being added to the table.
        !            72:  *
        !            73:  * Supplying this function is optional.
        !            74:  */
        !            75: typedef void   ghash_add_t(struct ghash *g, void *item);
        !            76: 
        !            77: /*
        !            78:  * Notification that an item is being removed from the table.
        !            79:  *
        !            80:  * Supplying this function is optional.
        !            81:  */
        !            82: typedef void   ghash_del_t(struct ghash *g, void *item);
        !            83: 
        !            84: /**********************************************************************
        !            85:                        HASH TABLE METHODS
        !            86: **********************************************************************/
        !            87: 
        !            88: __BEGIN_DECLS
        !            89: 
        !            90: /*
        !            91:  * Create a new hash table.
        !            92:  *
        !            93:  * "isize" is the initial table size, or zero for the default.
        !            94:  *
        !            95:  * "maxload" is the maximum hash table load in percent, or zero
        !            96:  * for the default which is 75 (i.e., 75%).
        !            97:  *
        !            98:  * The "hash", "equal", "add", and "del" methods are optional (see above).
        !            99:  */
        !           100: extern struct  ghash *ghash_create(void *arg, u_int isize, u_int maxload,
        !           101:                        const char *mtype, ghash_hash_t *hash,
        !           102:                        ghash_equal_t *equal, ghash_add_t *add,
        !           103:                        ghash_del_t *del);
        !           104: 
        !           105: /*
        !           106:  * Destroy a hash table.
        !           107:  *
        !           108:  * Any items remaining in the table will be removed first.
        !           109:  */
        !           110: extern void    ghash_destroy(struct ghash **gp);
        !           111: 
        !           112: /*
        !           113:  * Get the argument supplied to ghash_create().
        !           114:  */
        !           115: extern void    *ghash_arg(struct ghash *g);
        !           116: 
        !           117: /*
        !           118:  * Get an item.
        !           119:  *
        !           120:  * Returns the item, or NULL if the item does not exist.
        !           121:  */
        !           122: extern void    *ghash_get(struct ghash *g, const void *item);
        !           123: 
        !           124: /*
        !           125:  * Put an item.
        !           126:  *
        !           127:  * Returns 0 if the item is new, 1 if it replaces an existing
        !           128:  * item, and -1 if there was an error.
        !           129:  */
        !           130: extern int     ghash_put(struct ghash *g, const void *item);
        !           131: 
        !           132: /*
        !           133:  * Remove an item.
        !           134:  *
        !           135:  * Returns 1 if the item was found and removed, 0 if not found.
        !           136:  */
        !           137: extern int     ghash_remove(struct ghash *g, const void *item);
        !           138: 
        !           139: /*
        !           140:  * Get the size of the table.
        !           141:  */
        !           142: extern u_int   ghash_size(struct ghash *g);
        !           143: 
        !           144: /*
        !           145:  * Get an array of all items in the table.
        !           146:  *
        !           147:  * Returns number of items in the list, or -1 if error.
        !           148:  * Caller must free the list.
        !           149:  */
        !           150: extern int     ghash_dump(struct ghash *g, void ***listp, const char *mtype);
        !           151: 
        !           152: /*
        !           153:  * Start a hash table walk. Caller must supply a pointer to a
        !           154:  * 'struct ghash_walk' (see below) which is used to store the
        !           155:  * position in the table for ghash_walk_next().
        !           156:  */
        !           157: extern void    ghash_walk_init(struct ghash *g, struct ghash_walk *walk);
        !           158: 
        !           159: /*
        !           160:  * Get the next item in the hash table walk, or NULL if the walk
        !           161:  * is finished (ENOENT) or the table has been modified (EINVAL).
        !           162:  *
        !           163:  * This is only valid if the hash table has not been modified
        !           164:  * since the previous call to ghash_walk_init() or ghash_walk_next().
        !           165:  */
        !           166: extern void    *ghash_walk_next(struct ghash *g, struct ghash_walk *walk);
        !           167: 
        !           168: __END_DECLS
        !           169: 
        !           170: struct ghash_walk {
        !           171:        u_int           mods;
        !           172:        u_int           bucket;
        !           173:        struct gent     *e;
        !           174: };
        !           175: 
        !           176: /**********************************************************************
        !           177:                        ITERATOR METHODS
        !           178: **********************************************************************/
        !           179: 
        !           180: struct ghash_iter;
        !           181: 
        !           182: __BEGIN_DECLS
        !           183: 
        !           184: extern int     ghash_iter_has_next(struct ghash_iter *iter);
        !           185: extern void    *ghash_iter_next(struct ghash_iter *iter);
        !           186: extern int     ghash_iter_remove(struct ghash_iter *iter);
        !           187: 
        !           188: extern struct  ghash_iter *ghash_iter_create(struct ghash *g);
        !           189: extern void    ghash_iter_destroy(struct ghash_iter **iterp);
        !           190: 
        !           191: __END_DECLS
        !           192: 
        !           193: #endif /* _PDEL_UTIL_GHASH_H_ */
        !           194: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>