Move to kernel style SPDX license identifiers
[lttng-tools.git] / src / common / hashtable / hashtable.h
... / ...
CommitLineData
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
17extern unsigned long lttng_ht_seed;
18
19typedef unsigned long (*hash_fct)(const void *_key, unsigned long seed);
20typedef cds_lfht_match_fct hash_match_fct;
21
22enum lttng_ht_type {
23 LTTNG_HT_TYPE_STRING,
24 LTTNG_HT_TYPE_ULONG,
25 LTTNG_HT_TYPE_U64,
26 LTTNG_HT_TYPE_TWO_U64,
27};
28
29struct lttng_ht {
30 struct cds_lfht *ht;
31 cds_lfht_match_fct match_fct;
32 hash_fct hash_fct;
33};
34
35struct lttng_ht_iter {
36 struct cds_lfht_iter iter;
37};
38
39struct lttng_ht_node_str {
40 char *key;
41 struct cds_lfht_node node;
42 struct rcu_head head;
43};
44
45struct lttng_ht_node_ulong {
46 unsigned long key;
47 struct cds_lfht_node node;
48 struct rcu_head head;
49};
50
51struct lttng_ht_node_u64 {
52 uint64_t key;
53 struct cds_lfht_node node;
54 struct rcu_head head;
55};
56
57struct lttng_ht_two_u64 {
58 uint64_t key1;
59 uint64_t key2;
60};
61
62struct lttng_ht_node_two_u64 {
63 struct lttng_ht_two_u64 key;
64 struct cds_lfht_node node;
65 struct rcu_head head;
66};
67
68/* Hashtable new and destroy */
69LTTNG_HIDDEN
70struct lttng_ht *lttng_ht_new(unsigned long size, int type);
71LTTNG_HIDDEN
72void lttng_ht_destroy(struct lttng_ht *ht);
73
74/* Specialized node init and free functions */
75LTTNG_HIDDEN
76void lttng_ht_node_init_str(struct lttng_ht_node_str *node, char *key);
77LTTNG_HIDDEN
78void lttng_ht_node_init_ulong(struct lttng_ht_node_ulong *node,
79 unsigned long key);
80LTTNG_HIDDEN
81void lttng_ht_node_init_u64(struct lttng_ht_node_u64 *node,
82 uint64_t key);
83LTTNG_HIDDEN
84void lttng_ht_node_init_two_u64(struct lttng_ht_node_two_u64 *node,
85 uint64_t key1, uint64_t key2);
86LTTNG_HIDDEN
87void lttng_ht_node_free_str(struct lttng_ht_node_str *node);
88LTTNG_HIDDEN
89void lttng_ht_node_free_ulong(struct lttng_ht_node_ulong *node);
90LTTNG_HIDDEN
91void lttng_ht_node_free_u64(struct lttng_ht_node_u64 *node);
92LTTNG_HIDDEN
93void lttng_ht_node_free_two_u64(struct lttng_ht_node_two_u64 *node);
94
95LTTNG_HIDDEN
96void lttng_ht_lookup(struct lttng_ht *ht, const void *key,
97 struct lttng_ht_iter *iter);
98
99/* Specialized add unique functions */
100LTTNG_HIDDEN
101void lttng_ht_add_unique_str(struct lttng_ht *ht,
102 struct lttng_ht_node_str *node);
103LTTNG_HIDDEN
104void lttng_ht_add_unique_ulong(struct lttng_ht *ht,
105 struct lttng_ht_node_ulong *node);
106LTTNG_HIDDEN
107void lttng_ht_add_unique_u64(struct lttng_ht *ht,
108 struct lttng_ht_node_u64 *node);
109LTTNG_HIDDEN
110void lttng_ht_add_unique_two_u64(struct lttng_ht *ht,
111 struct lttng_ht_node_two_u64 *node);
112LTTNG_HIDDEN
113struct lttng_ht_node_ulong *lttng_ht_add_replace_ulong(
114 struct lttng_ht *ht, struct lttng_ht_node_ulong *node);
115LTTNG_HIDDEN
116struct lttng_ht_node_u64 *lttng_ht_add_replace_u64(
117 struct lttng_ht *ht, struct lttng_ht_node_u64 *node);
118LTTNG_HIDDEN
119void lttng_ht_add_str(struct lttng_ht *ht,
120 struct lttng_ht_node_str *node);
121LTTNG_HIDDEN
122void lttng_ht_add_ulong(struct lttng_ht *ht,
123 struct lttng_ht_node_ulong *node);
124LTTNG_HIDDEN
125void lttng_ht_add_u64(struct lttng_ht *ht,
126 struct lttng_ht_node_u64 *node);
127
128LTTNG_HIDDEN
129int lttng_ht_del(struct lttng_ht *ht, struct lttng_ht_iter *iter);
130
131LTTNG_HIDDEN
132void lttng_ht_get_first(struct lttng_ht *ht,
133 struct lttng_ht_iter *iter);
134LTTNG_HIDDEN
135void lttng_ht_get_next(struct lttng_ht *ht, struct lttng_ht_iter *iter);
136
137LTTNG_HIDDEN
138unsigned long lttng_ht_get_count(struct lttng_ht *ht);
139
140LTTNG_HIDDEN
141struct lttng_ht_node_str *lttng_ht_iter_get_node_str(
142 struct lttng_ht_iter *iter);
143LTTNG_HIDDEN
144struct lttng_ht_node_ulong *lttng_ht_iter_get_node_ulong(
145 struct lttng_ht_iter *iter);
146LTTNG_HIDDEN
147struct lttng_ht_node_u64 *lttng_ht_iter_get_node_u64(
148 struct lttng_ht_iter *iter);
149LTTNG_HIDDEN
150struct lttng_ht_node_two_u64 *lttng_ht_iter_get_node_two_u64(
151 struct lttng_ht_iter *iter);
152
153#endif /* _LTT_HT_H */
This page took 0.035177 seconds and 4 git commands to generate.