linkhash.h
Go to the documentation of this file.
00001 /*
00002  * $Id: linkhash.h,v 1.6 2006/01/30 23:07:57 mclark Exp $
00003  *
00004  * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
00005  * Michael Clark <michael@metaparadigm.com>
00006  *
00007  * This library is free software; you can redistribute it and/or modify
00008  * it under the terms of the MIT license. See COPYING for details.
00009  *
00010  */
00011  
00012 #ifndef _linkhash_h_
00013 #define _linkhash_h_
00014 
00018 #define LH_PRIME 0x9e370001UL
00019 
00023 #define LH_EMPTY (void*)-1
00024 
00028 #define LH_FREED (void*)-2
00029 
00030 struct lh_entry;
00031 
00035 typedef void (lh_entry_free_fn) (struct lh_entry *e);
00039 typedef unsigned long (lh_hash_fn) (void *k);
00043 typedef int (lh_equal_fn) (void *k1, void *k2);
00044 
00048 struct lh_entry {
00052         void *k;
00056         void *v;
00060         struct lh_entry *next;
00064         struct lh_entry *prev;
00065 };
00066 
00067 
00071 struct lh_table {
00075         int size;
00079         int count;
00080 
00084         int collisions;
00085 
00089         int resizes;
00090 
00094         int lookups;
00095 
00099         int inserts;
00100 
00104         int deletes;
00105 
00109         char *name;
00110 
00114         struct lh_entry *head;
00115 
00119         struct lh_entry *tail;
00120 
00121         struct lh_entry *table;
00122 
00126         lh_entry_free_fn *free_fn;
00127         lh_hash_fn *hash_fn;
00128         lh_equal_fn *equal_fn;
00129 };
00130 
00131 
00135 extern unsigned long lh_ptr_hash(void *k);
00136 extern int lh_ptr_equal(void *k1, void *k2);
00137 
00138 extern unsigned long lh_char_hash(void *k);
00139 extern int lh_char_equal(void *k1, void *k2);
00140 
00141 
00145 #define lh_foreach(table, entry) \
00146 for(entry = table->head; entry; entry = entry->next)
00147 
00151 #define lh_foreach_safe(table, entry, tmp) \
00152 for(entry = table->head; entry && ((tmp = entry->next) || 1); entry = tmp)
00153 
00154 
00155 
00173 extern struct lh_table* lh_table_new(int size, char *name,
00174                                      lh_entry_free_fn *free_fn,
00175                                      lh_hash_fn *hash_fn,
00176                                      lh_equal_fn *equal_fn);
00177 
00186 extern struct lh_table* lh_kchar_table_new(int size, char *name,
00187                                            lh_entry_free_fn *free_fn);
00188 
00189 
00198 extern struct lh_table* lh_kptr_table_new(int size, char *name,
00199                                           lh_entry_free_fn *free_fn);
00200 
00201 
00208 extern void lh_table_free(struct lh_table *t);
00209 
00210 
00217 extern int lh_table_insert(struct lh_table *t, void *k, void *v);
00218 
00219 
00226 extern struct lh_entry* lh_table_lookup_entry(struct lh_table *t, void *k);
00227 
00234 extern void* lh_table_lookup(struct lh_table *t, void *k);
00235 
00236 
00246 extern int lh_table_delete_entry(struct lh_table *t, struct lh_entry *e);
00247 
00248 
00258 extern int lh_table_delete(struct lh_table *t, void *k);
00259 
00260 
00261 #endif


csm
Author(s): Andrea Censi
autogenerated on Fri May 17 2019 02:28:33