1 /* 2 * Copyright 2001-2004 Brandon Long 3 * All Rights Reserved. 4 * 5 * ClearSilver Templating System 6 * 7 * This code is made available under the terms of the ClearSilver License. 8 * http://www.clearsilver.net/license.hdf 9 * 10 */ 11 12 #ifndef __NEO_HASH_H_ 13 #define __NEO_HASH_H_ 1 14 15 __BEGIN_DECLS 16 17 #include <stdlib.h> 18 #include "util/neo_misc.h" 19 20 typedef UINT32 (*NE_HASH_FUNC)(const void *); 21 typedef int (*NE_COMP_FUNC)(const void *, const void *); 22 23 typedef struct _NE_HASHNODE 24 { 25 void *key; 26 void *value; 27 UINT32 hashv; 28 struct _NE_HASHNODE *next; 29 } NE_HASHNODE; 30 31 typedef struct _HASH 32 { 33 UINT32 size; 34 UINT32 num; 35 36 NE_HASHNODE **nodes; 37 NE_HASH_FUNC hash_func; 38 NE_COMP_FUNC comp_func; 39 } NE_HASH; 40 41 NEOERR *ne_hash_init (NE_HASH **hash, NE_HASH_FUNC hash_func, NE_COMP_FUNC comp_func); 42 void ne_hash_destroy (NE_HASH **hash); 43 NEOERR *ne_hash_insert(NE_HASH *hash, void *key, void *value); 44 void *ne_hash_lookup(NE_HASH *hash, void *key); 45 int ne_hash_has_key(NE_HASH *hash, void *key); 46 void *ne_hash_remove(NE_HASH *hash, void *key); 47 void *ne_hash_next(NE_HASH *hash, void **key); 48 49 int ne_hash_str_comp(const void *a, const void *b); 50 UINT32 ne_hash_str_hash(const void *a); 51 52 int ne_hash_int_comp(const void *a, const void *b); 53 UINT32 ne_hash_int_hash(const void *a); 54 55 __END_DECLS 56 57 #endif /* __NEO_HASH_H_ */ 58