e2dae968d0040de1136f40a689018099eb2fc538
[lttng-tools.git] / src / common / hashtable / hashtable.h
1 /*
2 * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8 #ifndef _LTT_HT_H
9 #define _LTT_HT_H
10
11 #include <urcu.h>
12 #include <stdint.h>
13
14 #include <common/macros.h>
15 #include <urcu/rculfhash.h>
16
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20
21 extern unsigned long lttng_ht_seed;
22
23 typedef unsigned long (*hash_fct_type)(const void *_key, unsigned long seed);
24 typedef cds_lfht_match_fct hash_match_fct;
25
26 enum lttng_ht_type {
27 LTTNG_HT_TYPE_STRING,
28 LTTNG_HT_TYPE_ULONG,
29 LTTNG_HT_TYPE_U64,
30 LTTNG_HT_TYPE_TWO_U64,
31 };
32
33 struct lttng_ht {
34 struct cds_lfht *ht;
35 cds_lfht_match_fct match_fct;
36 hash_fct_type hash_fct;
37 };
38
39 struct lttng_ht_iter {
40 struct cds_lfht_iter iter;
41 };
42
43 struct lttng_ht_node_str {
44 char *key;
45 struct cds_lfht_node node;
46 struct rcu_head head;
47 };
48
49 struct lttng_ht_node_ulong {
50 unsigned long key;
51 struct cds_lfht_node node;
52 struct rcu_head head;
53 };
54
55 struct lttng_ht_node_u64 {
56 uint64_t key;
57 struct cds_lfht_node node;
58 struct rcu_head head;
59 };
60
61 struct lttng_ht_two_u64 {
62 uint64_t key1;
63 uint64_t key2;
64 };
65
66 struct lttng_ht_node_two_u64 {
67 struct lttng_ht_two_u64 key;
68 struct cds_lfht_node node;
69 struct rcu_head head;
70 };
71
72 /* Hashtable new and destroy */
73 struct lttng_ht *lttng_ht_new(unsigned long size, int type);
74 void lttng_ht_destroy(struct lttng_ht *ht);
75
76 /* Specialized node init and free functions */
77 void lttng_ht_node_init_str(struct lttng_ht_node_str *node, char *key);
78 void lttng_ht_node_init_ulong(struct lttng_ht_node_ulong *node,
79 unsigned long key);
80 void lttng_ht_node_init_u64(struct lttng_ht_node_u64 *node,
81 uint64_t key);
82 void lttng_ht_node_init_two_u64(struct lttng_ht_node_two_u64 *node,
83 uint64_t key1, uint64_t key2);
84 void lttng_ht_node_free_str(struct lttng_ht_node_str *node);
85 void lttng_ht_node_free_ulong(struct lttng_ht_node_ulong *node);
86 void lttng_ht_node_free_u64(struct lttng_ht_node_u64 *node);
87 void lttng_ht_node_free_two_u64(struct lttng_ht_node_two_u64 *node);
88
89 void lttng_ht_lookup(struct lttng_ht *ht, const void *key,
90 struct lttng_ht_iter *iter);
91
92 /* Specialized add unique functions */
93 void lttng_ht_add_unique_str(struct lttng_ht *ht,
94 struct lttng_ht_node_str *node);
95 void lttng_ht_add_unique_ulong(struct lttng_ht *ht,
96 struct lttng_ht_node_ulong *node);
97 void lttng_ht_add_unique_u64(struct lttng_ht *ht,
98 struct lttng_ht_node_u64 *node);
99 void lttng_ht_add_unique_two_u64(struct lttng_ht *ht,
100 struct lttng_ht_node_two_u64 *node);
101 struct lttng_ht_node_ulong *lttng_ht_add_replace_ulong(
102 struct lttng_ht *ht, struct lttng_ht_node_ulong *node);
103 struct lttng_ht_node_u64 *lttng_ht_add_replace_u64(
104 struct lttng_ht *ht, struct lttng_ht_node_u64 *node);
105 void lttng_ht_add_str(struct lttng_ht *ht,
106 struct lttng_ht_node_str *node);
107 void lttng_ht_add_ulong(struct lttng_ht *ht,
108 struct lttng_ht_node_ulong *node);
109 void lttng_ht_add_u64(struct lttng_ht *ht,
110 struct lttng_ht_node_u64 *node);
111
112 int lttng_ht_del(struct lttng_ht *ht, struct lttng_ht_iter *iter);
113
114 void lttng_ht_get_first(struct lttng_ht *ht,
115 struct lttng_ht_iter *iter);
116 void lttng_ht_get_next(struct lttng_ht *ht, struct lttng_ht_iter *iter);
117
118 unsigned long lttng_ht_get_count(struct lttng_ht *ht);
119
120 struct lttng_ht_node_str *lttng_ht_iter_get_node_str(
121 struct lttng_ht_iter *iter);
122 struct lttng_ht_node_ulong *lttng_ht_iter_get_node_ulong(
123 struct lttng_ht_iter *iter);
124 struct lttng_ht_node_u64 *lttng_ht_iter_get_node_u64(
125 struct lttng_ht_iter *iter);
126 struct lttng_ht_node_two_u64 *lttng_ht_iter_get_node_two_u64(
127 struct lttng_ht_iter *iter);
128
129 #ifdef __cplusplus
130 }
131 #endif
132
133 #endif /* _LTT_HT_H */
This page took 0.031266 seconds and 3 git commands to generate.