linkhash.h
Go to the documentation of this file.
1 /*
2  * $Id: linkhash.h,v 1.6 2006/01/30 23:07:57 mclark Exp $
3  *
4  * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
5  * Michael Clark <michael@metaparadigm.com>
6  *
7  * This library is free software; you can redistribute it and/or modify
8  * it under the terms of the MIT license. See COPYING for details.
9  *
10  */
11 
12 #ifndef _linkhash_h_
13 #define _linkhash_h_
14 
18 #define LH_PRIME 0x9e370001UL
19 
23 #define LH_EMPTY (void*)-1
24 
28 #define LH_FREED (void*)-2
29 
30 struct lh_entry;
31 
35 typedef void (lh_entry_free_fn) (struct lh_entry *e);
39 typedef unsigned long (lh_hash_fn) (void *k);
43 typedef int (lh_equal_fn) (void *k1, void *k2);
44 
48 struct lh_entry {
52  void *k;
56  void *v;
60  struct lh_entry *next;
64  struct lh_entry *prev;
65 };
66 
67 
71 struct lh_table {
75  int size;
79  int count;
80 
85 
89  int resizes;
90 
94  int lookups;
95 
99  int inserts;
100 
104  int deletes;
105 
109  char *name;
110 
114  struct lh_entry *head;
115 
119  struct lh_entry *tail;
120 
121  struct lh_entry *table;
122 
129 };
130 
131 
135 extern unsigned long lh_ptr_hash(void *k);
136 extern int lh_ptr_equal(void *k1, void *k2);
137 
138 extern unsigned long lh_char_hash(void *k);
139 extern int lh_char_equal(void *k1, void *k2);
140 
141 
145 #define lh_foreach(table, entry) \
146 for(entry = table->head; entry; entry = entry->next)
147 
151 #define lh_foreach_safe(table, entry, tmp) \
152 for(entry = table->head; entry && ((tmp = entry->next) || 1); entry = tmp)
153 
154 
155 
173 extern struct lh_table* lh_table_new(int size, char *name,
177 
186 extern struct lh_table* lh_kchar_table_new(int size, char *name,
188 
189 
198 extern struct lh_table* lh_kptr_table_new(int size, char *name,
200 
201 
208 extern void lh_table_free(struct lh_table *t);
209 
210 
217 extern int lh_table_insert(struct lh_table *t, void *k, void *v);
218 
219 
226 extern struct lh_entry* lh_table_lookup_entry(struct lh_table *t, void *k);
227 
234 extern void* lh_table_lookup(struct lh_table *t, void *k);
235 
236 
246 extern int lh_table_delete_entry(struct lh_table *t, struct lh_entry *e);
247 
248 
258 extern int lh_table_delete(struct lh_table *t, void *k);
259 
260 
261 #endif
lh_table::resizes
int resizes
Definition: linkhash.h:89
lh_table::name
char * name
Definition: linkhash.h:109
lh_equal_fn
int() lh_equal_fn(void *k1, void *k2)
Definition: linkhash.h:43
lh_char_equal
int lh_char_equal(void *k1, void *k2)
Definition: linkhash.c:52
lh_table_delete_entry
int lh_table_delete_entry(struct lh_table *t, struct lh_entry *e)
Definition: linkhash.c:182
lh_table
Definition: linkhash.h:71
lh_table::tail
struct lh_entry * tail
Definition: linkhash.h:119
lh_table::size
int size
Definition: linkhash.h:75
lh_table::count
int count
Definition: linkhash.h:79
lh_table::lookups
int lookups
Definition: linkhash.h:94
lh_table::table
struct lh_entry * table
Definition: linkhash.h:121
lh_char_hash
unsigned long lh_char_hash(void *k)
Definition: linkhash.c:42
lh_entry::v
void * v
Definition: linkhash.h:56
lh_table_new
struct lh_table * lh_table_new(int size, char *name, lh_entry_free_fn *free_fn, lh_hash_fn *hash_fn, lh_equal_fn *equal_fn)
Definition: linkhash.c:57
lh_table_lookup
void * lh_table_lookup(struct lh_table *t, void *k)
Definition: linkhash.c:174
lh_ptr_equal
int lh_ptr_equal(void *k1, void *k2)
Definition: linkhash.c:37
lh_table::deletes
int deletes
Definition: linkhash.h:104
lh_table::hash_fn
lh_hash_fn * hash_fn
Definition: linkhash.h:127
lh_table::head
struct lh_entry * head
Definition: linkhash.h:114
lh_table_insert
int lh_table_insert(struct lh_table *t, void *k, void *v)
Definition: linkhash.c:124
lh_table_lookup_entry
struct lh_entry * lh_table_lookup_entry(struct lh_table *t, void *k)
Definition: linkhash.c:158
lh_entry::prev
struct lh_entry * prev
Definition: linkhash.h:64
lh_table::equal_fn
lh_equal_fn * equal_fn
Definition: linkhash.h:128
lh_entry
Definition: linkhash.h:48
lh_table_delete
int lh_table_delete(struct lh_table *t, void *k)
Definition: linkhash.c:211
lh_table::collisions
int collisions
Definition: linkhash.h:84
lh_entry::next
struct lh_entry * next
Definition: linkhash.h:60
lh_entry::k
void * k
Definition: linkhash.h:52
lh_kchar_table_new
struct lh_table * lh_kchar_table_new(int size, char *name, lh_entry_free_fn *free_fn)
Definition: linkhash.c:79
lh_ptr_hash
unsigned long lh_ptr_hash(void *k)
Definition: linkhash.c:31
lh_hash_fn
unsigned long() lh_hash_fn(void *k)
Definition: linkhash.h:39
lh_kptr_table_new
struct lh_table * lh_kptr_table_new(int size, char *name, lh_entry_free_fn *free_fn)
Definition: linkhash.c:85
lh_table_free
void lh_table_free(struct lh_table *t)
Definition: linkhash.c:111
lh_entry_free_fn
void() lh_entry_free_fn(struct lh_entry *e)
Definition: linkhash.h:35
lh_table::inserts
int inserts
Definition: linkhash.h:99
lh_table::free_fn
lh_entry_free_fn * free_fn
Definition: linkhash.h:126


csm
Author(s): Andrea Censi
autogenerated on Wed Aug 17 2022 02:50:33