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