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