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
int( lh_equal_fn)(void *k1, void *k2)
Definition: linkhash.h:43
int collisions
Definition: linkhash.h:84
lh_entry_free_fn * free_fn
Definition: linkhash.h:126
int lookups
Definition: linkhash.h:94
struct lh_entry * lh_table_lookup_entry(struct lh_table *t, void *k)
Definition: linkhash.c:158
struct lh_entry * tail
Definition: linkhash.h:119
void * v
Definition: linkhash.h:56
int resizes
Definition: linkhash.h:89
struct lh_entry * next
Definition: linkhash.h:60
int lh_ptr_equal(void *k1, void *k2)
Definition: linkhash.c:37
void * lh_table_lookup(struct lh_table *t, void *k)
Definition: linkhash.c:174
unsigned long( lh_hash_fn)(void *k)
Definition: linkhash.h:39
unsigned long lh_ptr_hash(void *k)
Definition: linkhash.c:31
struct lh_entry * table
Definition: linkhash.h:121
int size
Definition: linkhash.h:75
void * k
Definition: linkhash.h:52
int deletes
Definition: linkhash.h:104
struct lh_entry * prev
Definition: linkhash.h:64
lh_hash_fn * hash_fn
Definition: linkhash.h:127
int lh_char_equal(void *k1, void *k2)
Definition: linkhash.c:52
unsigned long lh_char_hash(void *k)
Definition: linkhash.c:42
int lh_table_delete(struct lh_table *t, void *k)
Definition: linkhash.c:211
void lh_table_free(struct lh_table *t)
Definition: linkhash.c:111
void( lh_entry_free_fn)(struct lh_entry *e)
Definition: linkhash.h:35
struct lh_table * lh_kchar_table_new(int size, char *name, lh_entry_free_fn *free_fn)
Definition: linkhash.c:79
struct lh_entry * head
Definition: linkhash.h:114
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_equal_fn * equal_fn
Definition: linkhash.h:128
Definition: linkhash.h:48
int lh_table_delete_entry(struct lh_table *t, struct lh_entry *e)
Definition: linkhash.c:182
struct lh_table * lh_kptr_table_new(int size, char *name, lh_entry_free_fn *free_fn)
Definition: linkhash.c:85
int inserts
Definition: linkhash.h:99
int count
Definition: linkhash.h:79
int lh_table_insert(struct lh_table *t, void *k, void *v)
Definition: linkhash.c:124
char * name
Definition: linkhash.h:109


csm
Author(s): Andrea Censi
autogenerated on Tue May 11 2021 02:18:23