1 /* 2 * jabberd - Jabber Open Source Server 3 * Copyright (c) 2002-2004 Jeremie Miller, Thomas Muldowney, 4 * Ryan Eatmon, Robert Norris 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 */ 20 21 /** @file util/xhash.h 22 * @brief hashtables 23 * $Date: 2004/04/30 00:53:55 $ 24 * $Revision: 1.1 $ 25 */ 26 27 #ifndef INCL_UTIL_XHASH_H 28 #define INCL_UTIL_XHASH_H 1 29 30 #ifdef HAVE_CONFIG_H 31 # include <config.h> 32 #endif 33 34 #include "pool.h" 35 36 typedef struct xhn_struct 37 { 38 struct xhn_struct *next; 39 struct xhn_struct *prev; 40 const char *key; 41 int keylen; 42 void *val; 43 } *xhn, _xhn; 44 45 typedef struct xht_struct 46 { 47 pool_t p; 48 int prime; 49 int dirty; 50 int count; 51 struct xhn_struct *zen; 52 struct xhn_struct *free_list; // list of zaped elements to be reused. 53 int iter_bucket; 54 xhn iter_node; 55 int *stat; 56 } *xht, _xht; 57 58 JABBERD2_API xht xhash_new(int prime); 59 JABBERD2_API void xhash_put(xht h, const char *key, void *val); 60 JABBERD2_API void xhash_putx(xht h, const char *key, int len, void *val); 61 JABBERD2_API void *xhash_get(xht h, const char *key); 62 JABBERD2_API void *xhash_getx(xht h, const char *key, int len); 63 JABBERD2_API void xhash_zap(xht h, const char *key); 64 JABBERD2_API void xhash_zapx(xht h, const char *key, int len); 65 JABBERD2_API void xhash_stat(xht h); 66 JABBERD2_API void xhash_free(xht h); 67 typedef void (*xhash_walker)(const char *key, int keylen, void *val, void *arg); 68 JABBERD2_API void xhash_walk(xht h, xhash_walker w, void *arg); 69 JABBERD2_API int xhash_dirty(xht h); 70 JABBERD2_API int xhash_count(xht h); 71 JABBERD2_API pool_t xhash_pool(xht h); 72 73 /* iteration functions */ 74 JABBERD2_API int xhash_iter_first(xht h); 75 JABBERD2_API int xhash_iter_next(xht h); 76 JABBERD2_API void xhash_iter_zap(xht h); 77 JABBERD2_API int xhash_iter_get(xht h, const char **key, int *keylen, void **val); 78 79 #endif 80