rculfhash: document algorithms
[urcu.git] / urcu / rculfhash.h
1 #ifndef _URCU_RCULFHASH_H
2 #define _URCU_RCULFHASH_H
3
4 #include <stdint.h>
5 #include <urcu-call-rcu.h>
6
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10
11 struct _rcu_ht_node {
12 struct rcu_ht_node *next; /* ptr | DUMMY_FLAG | REMOVED_FLAG */
13 unsigned long reverse_hash;
14 };
15
16 struct rcu_ht_node {
17 /* cache-hot for iteration */
18 struct _rcu_ht_node p; /* needs to be first field */
19 void *key;
20 unsigned int key_len;
21 /* cache-cold for iteration */
22 struct rcu_head head;
23 };
24
25 struct rcu_ht;
26
27 /*
28 * Caution !
29 * Ensure reader and writer threads are registered as urcu readers.
30 */
31
32 typedef unsigned long (*ht_hash_fct)(void *key, size_t length,
33 unsigned long seed);
34 typedef unsigned long (*ht_compare_fct)(void *key1, size_t key1_len,
35 void *key2, size_t key2_len);
36
37 static inline
38 void ht_node_init(struct rcu_ht_node *node, void *key,
39 size_t key_len)
40 {
41 node->key = key;
42 node->key_len = key_len;
43 }
44
45 /*
46 * init_size must be power of two.
47 */
48 struct rcu_ht *ht_new(ht_hash_fct hash_fct,
49 ht_compare_fct compare_fct,
50 unsigned long hash_seed,
51 unsigned long init_size,
52 void (*ht_call_rcu)(struct rcu_head *head,
53 void (*func)(struct rcu_head *head)));
54
55 int ht_destroy(struct rcu_ht *ht);
56 /* Count the number of nodes in the hash table. Call with rcu_read_lock held. */
57 void ht_count_nodes(struct rcu_ht *ht,
58 unsigned long *count,
59 unsigned long *removed);
60
61 /* Call with rcu_read_lock held. */
62 struct rcu_ht_node *ht_lookup(struct rcu_ht *ht, void *key, size_t key_len);
63
64 /* Call with rcu_read_lock held. */
65 void ht_add(struct rcu_ht *ht, struct rcu_ht_node *node);
66
67 /*
68 * Call with rcu_read_lock held.
69 * Returns the node added upon success.
70 * Returns the unique node already present upon failure. If ht_add_unique fails,
71 * the node passed as parameter should be freed by the caller.
72 */
73 struct rcu_ht_node *ht_add_unique(struct rcu_ht *ht, struct rcu_ht_node *node);
74
75 /* Call with rcu_read_lock held. */
76 int ht_remove(struct rcu_ht *ht, struct rcu_ht_node *node);
77
78 void ht_resize(struct rcu_ht *ht, int growth);
79
80 #ifdef __cplusplus
81 }
82 #endif
83
84 #endif /* _URCU_RCULFHASH_H */
This page took 0.033596 seconds and 5 git commands to generate.