MACSio  0.9
Multi-purpose, Application-Centric, Scalable I/O Proxy App
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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  * Copyright (c) 2009 Hewlett-Packard Development Company, L.P.
7  *
8  * This library is free software; you can redistribute it and/or modify
9  * it under the terms of the MIT license. See COPYING for details.
10  *
11  */
12 
13 #ifndef _linkhash_h_
14 #define _linkhash_h_
15 
16 #include "json_object.h"
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
25 #define LH_PRIME 0x9e370001UL
26 
32 #define LH_LOAD_FACTOR 0.66
33 
37 #define LH_EMPTY (void*)-1
38 
42 #define LH_FREED (void*)-2
43 
44 struct lh_entry;
45 
49 typedef void (lh_entry_free_fn) (struct lh_entry *e);
53 typedef unsigned long (lh_hash_fn) (const void *k);
57 typedef int (lh_equal_fn) (const void *k1, const void *k2);
58 
62 struct lh_entry {
66  void *k;
70  const void *v;
74  struct lh_entry *next;
78  struct lh_entry *prev;
79 };
80 
81 
85 struct lh_table {
89  int size;
93  int count;
94 
99 
103  int resizes;
104 
108  int lookups;
109 
113  int inserts;
114 
118  int deletes;
119 
123  const char *name;
124 
128  struct lh_entry *head;
129 
133  struct lh_entry *tail;
134 
135  struct lh_entry *table;
136 
143 };
144 
145 
149 extern unsigned long lh_ptr_hash(const void *k);
150 extern int lh_ptr_equal(const void *k1, const void *k2);
151 
152 extern unsigned long lh_char_hash(const void *k);
153 extern int lh_char_equal(const void *k1, const void *k2);
154 
155 
159 #define lh_foreach(table, entry) \
160 for(entry = table->head; entry; entry = entry->next)
161 
165 #define lh_foreach_safe(table, entry, tmp) \
166 for(entry = table->head; entry && ((tmp = entry->next) || 1); entry = tmp)
167 
168 
169 
187 extern struct lh_table* lh_table_new(int size, const char *name,
191 
200 extern struct lh_table* lh_kchar_table_new(int size, const char *name,
202 
203 
212 extern struct lh_table* lh_kptr_table_new(int size, const char *name,
214 
215 
222 extern void lh_table_free(struct lh_table *t);
223 
224 
231 extern int lh_table_insert(struct lh_table *t, void *k, const void *v);
232 
233 
240 extern struct lh_entry* lh_table_lookup_entry(struct lh_table *t, const void *k);
241 
249 THIS_FUNCTION_IS_DEPRECATED(extern const void* lh_table_lookup(struct lh_table *t, const void *k));
250 
258 extern json_bool lh_table_lookup_ex(struct lh_table *t, const void *k, void **v);
259 
269 extern int lh_table_delete_entry(struct lh_table *t, struct lh_entry *e);
270 
271 
281 extern int lh_table_delete(struct lh_table *t, const void *k);
282 
283 extern int lh_table_length(struct lh_table *t);
284 
285 void lh_abort(const char *msg, ...);
286 void lh_table_resize(struct lh_table *t, int new_size);
287 
288 #ifdef __cplusplus
289 }
290 #endif
291 
292 #endif
int lh_table_insert(struct lh_table *t, void *k, const void *v)
Definition: linkhash.c:493
int collisions
Definition: linkhash.h:98
Definition: linkhash.h:62
struct lh_table * lh_table_new(int size, const char *name, lh_entry_free_fn *free_fn, lh_hash_fn *hash_fn, lh_equal_fn *equal_fn)
Definition: linkhash.c:426
int size
Definition: linkhash.h:89
int( lh_equal_fn)(const void *k1, const void *k2)
Definition: linkhash.h:57
json_bool lh_table_lookup_ex(struct lh_table *t, const void *k, void **v)
Definition: linkhash.c:552
struct lh_entry * table
Definition: linkhash.h:135
void lh_table_resize(struct lh_table *t, int new_size)
Definition: linkhash.c:460
unsigned long( lh_hash_fn)(const void *k)
Definition: linkhash.h:53
struct lh_entry * head
Definition: linkhash.h:128
int json_bool
Definition: json_object.h:80
int count
Definition: linkhash.h:93
THIS_FUNCTION_IS_DEPRECATED(extern const void *lh_table_lookup(struct lh_table *t, const void *k))
int lh_table_length(struct lh_table *t)
Definition: linkhash.c:599
const void * lh_table_lookup(struct lh_table *t, const void *k)
Definition: linkhash.c:545
int lh_ptr_equal(const void *k1, const void *k2)
Definition: linkhash.c:42
struct lh_table * lh_kptr_table_new(int size, const char *name, lh_entry_free_fn *free_fn)
Definition: linkhash.c:454
int inserts
Definition: linkhash.h:113
int lh_char_equal(const void *k1, const void *k2)
Definition: linkhash.c:421
void lh_table_free(struct lh_table *t)
Definition: linkhash.c:480
struct lh_entry * next
Definition: linkhash.h:74
void( lh_entry_free_fn)(struct lh_entry *e)
Definition: linkhash.h:49
const char * name
Definition: linkhash.h:123
unsigned long lh_char_hash(const void *k)
Definition: linkhash.c:400
int deletes
Definition: linkhash.h:118
lh_hash_fn * hash_fn
Definition: linkhash.h:141
struct lh_entry * tail
Definition: linkhash.h:133
lh_equal_fn * equal_fn
Definition: linkhash.h:142
int lookups
Definition: linkhash.h:108
struct lh_table * lh_kchar_table_new(int size, const char *name, lh_entry_free_fn *free_fn)
Definition: linkhash.c:448
struct lh_entry * prev
Definition: linkhash.h:78
int resizes
Definition: linkhash.h:103
unsigned long lh_ptr_hash(const void *k)
Definition: linkhash.c:36
struct lh_entry * lh_table_lookup_entry(struct lh_table *t, const void *k)
Definition: linkhash.c:527
const void * v
Definition: linkhash.h:70
void * k
Definition: linkhash.h:66
lh_entry_free_fn * free_fn
Definition: linkhash.h:140
void lh_abort(const char *msg,...)
Definition: linkhash.c:27
int lh_table_delete(struct lh_table *t, const void *k)
Definition: linkhash.c:592
int lh_table_delete_entry(struct lh_table *t, struct lh_entry *e)
Definition: linkhash.c:563