CAFE
Computational Analysis of gene Family Evolution
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hashtable.h
Go to the documentation of this file.
1 
7 #ifndef _HASHTABLE_H
8 #define _HASHTABLE_H
9 
10 #include<sys/types.h>
11 #include<stdint.h>
12 
13 #define HASH_LEN table->key_num
14 #define HASH(x,y) hash_table_do_hash(x,y,HASH_LEN)
15 
16 // forward declaration
18 
24 {
28  size_t key_len;
32  size_t value_len;
36  void * key;
40  void * value;
45 };
46 #define hash_table_element_s sizeof(hash_table_element_t)
47 
51 typedef enum hash_table_mode{
59 
64 typedef struct hash_table
65 {
70 
75 
79  size_t key_count;
80 
84  uint16_t key_num;
85 
89  size_t key_ratio;
90 
91 } hash_table_t;
92 #define hash_table_s sizeof(hash_table_t)
93 
94 
95 // element operations
102 
109 
117 uint16_t hash_table_do_hash(void * key, size_t key_len, uint16_t max_key);
118 
119 // hash table operations
127 
133 
143 #define HT_ADD(table, key, value) hash_table_add(table, (void *) key, sizeof(*key), (void *) value, sizeof(*value))
144 
155 int hash_table_add(hash_table_t *, void *, size_t, void *, size_t);
156 
165 #define HT_REMOVE(table, key) hash_table_remove(table, key, sizeof(*key))
166 
175 int hash_table_remove(hash_table_t *, void *, size_t);
176 
184 #define HT_LOOKUP(table, key) hash_table_lookup(table, key, sizeof(*key))
185 
195 void * hash_table_lookup(hash_table_t *, void *, size_t);
196 
204 #define HT_HAS_KEY(table, key) hash_table_has_key(table, key, sizeof(*key))
205 
213 int hash_table_has_key(hash_table_t *, void *, size_t);
214 
221 size_t hash_table_get_keys(hash_table_t *, void ***);
222 
231 
240 int hash_table_resize(hash_table_t *, size_t);
241 
249 int hash_table_iterate(hash_table_t *table, int (*fct)(void *user,
250  void *value, void *key, size_t key_len), void *user);
251 #endif
uint16_t hash_table_do_hash(void *key, size_t key_len, uint16_t max_key)
Definition: hashtable.c:432
int hash_table_iterate(hash_table_t *table, int(*fct)(void *user, void *value, void *key, size_t key_len), void *user)
Definition: hashtable.c:505
int hash_table_add(hash_table_t *, void *, size_t, void *, size_t)
Definition: hashtable.c:104
Definition: hashtable.h:55
void * hash_table_lookup(hash_table_t *, void *, size_t)
Definition: hashtable.c:276
struct hash_table hash_table_t
hash_table_element_t ** store_house
Definition: hashtable.h:69
size_t hash_table_get_elements(hash_table_t *, hash_table_element_t ***)
Definition: hashtable.c:390
Definition: hashtable.h:53
hash_table_mode
Definition: hashtable.h:51
int hash_table_resize(hash_table_t *, size_t)
Definition: hashtable.c:460
size_t hash_table_get_keys(hash_table_t *, void ***)
Definition: hashtable.c:352
size_t key_count
Definition: hashtable.h:79
size_t key_len
Definition: hashtable.h:28
Definition: hashtable.h:57
int hash_table_remove(hash_table_t *, void *, size_t)
Definition: hashtable.c:219
void * value
Definition: hashtable.h:40
void * key
Definition: hashtable.h:36
hash_table_t * hash_table_new(hash_table_mode_t)
Definition: hashtable.c:51
hash_table_mode_t mode
Definition: hashtable.h:74
size_t value_len
Definition: hashtable.h:32
size_t key_ratio
Definition: hashtable.h:89
hash_table_element_t * hash_table_element_new()
Definition: hashtable.c:18
stores an hash table element for use in the hash table
Definition: hashtable.h:23
void hash_table_delete(hash_table_t *)
Definition: hashtable.c:77
enum hash_table_mode hash_table_mode_t
uint16_t key_num
Definition: hashtable.h:84
identifies the hashtable for which operations are to be performed
Definition: hashtable.h:64
hash_table_element_t * next
Definition: hashtable.h:44
int hash_table_has_key(hash_table_t *, void *, size_t)
Definition: hashtable.c:316
void hash_table_element_delete(hash_table_t *, hash_table_element_t *)
Definition: hashtable.c:29