Cleanup: remove duplicated implementation of rculfhash
[lttng-tools.git] / src / common / hashtable / hashtable.h
... / ...
CommitLineData
1/*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2 only,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18#ifndef _LTT_HT_H
19#define _LTT_HT_H
20
21#include <urcu.h>
22#include <stdint.h>
23
24#include <common/macros.h>
25#include <urcu/rculfhash.h>
26
27extern unsigned long lttng_ht_seed;
28
29typedef unsigned long (*hash_fct)(void *_key, unsigned long seed);
30typedef cds_lfht_match_fct hash_match_fct;
31
32enum lttng_ht_type {
33 LTTNG_HT_TYPE_STRING,
34 LTTNG_HT_TYPE_ULONG,
35 LTTNG_HT_TYPE_U64,
36 LTTNG_HT_TYPE_TWO_U64,
37};
38
39struct lttng_ht {
40 struct cds_lfht *ht;
41 cds_lfht_match_fct match_fct;
42 hash_fct hash_fct;
43};
44
45struct lttng_ht_iter {
46 struct cds_lfht_iter iter;
47};
48
49struct lttng_ht_node_str {
50 char *key;
51 struct cds_lfht_node node;
52 struct rcu_head head;
53};
54
55struct lttng_ht_node_ulong {
56 unsigned long key;
57 struct cds_lfht_node node;
58 struct rcu_head head;
59};
60
61struct lttng_ht_node_u64 {
62 uint64_t key;
63 struct cds_lfht_node node;
64 struct rcu_head head;
65};
66
67struct lttng_ht_two_u64 {
68 uint64_t key1;
69 uint64_t key2;
70};
71
72struct lttng_ht_node_two_u64 {
73 struct lttng_ht_two_u64 key;
74 struct cds_lfht_node node;
75 struct rcu_head head;
76};
77
78/* Hashtable new and destroy */
79LTTNG_HIDDEN
80struct lttng_ht *lttng_ht_new(unsigned long size, int type);
81LTTNG_HIDDEN
82void lttng_ht_destroy(struct lttng_ht *ht);
83
84/* Specialized node init and free functions */
85LTTNG_HIDDEN
86void lttng_ht_node_init_str(struct lttng_ht_node_str *node, char *key);
87LTTNG_HIDDEN
88void lttng_ht_node_init_ulong(struct lttng_ht_node_ulong *node,
89 unsigned long key);
90LTTNG_HIDDEN
91void lttng_ht_node_init_u64(struct lttng_ht_node_u64 *node,
92 uint64_t key);
93LTTNG_HIDDEN
94void lttng_ht_node_init_two_u64(struct lttng_ht_node_two_u64 *node,
95 uint64_t key1, uint64_t key2);
96LTTNG_HIDDEN
97void lttng_ht_node_free_str(struct lttng_ht_node_str *node);
98LTTNG_HIDDEN
99void lttng_ht_node_free_ulong(struct lttng_ht_node_ulong *node);
100LTTNG_HIDDEN
101void lttng_ht_node_free_u64(struct lttng_ht_node_u64 *node);
102LTTNG_HIDDEN
103void lttng_ht_node_free_two_u64(struct lttng_ht_node_two_u64 *node);
104
105LTTNG_HIDDEN
106void lttng_ht_lookup(struct lttng_ht *ht, void *key,
107 struct lttng_ht_iter *iter);
108
109/* Specialized add unique functions */
110LTTNG_HIDDEN
111void lttng_ht_add_unique_str(struct lttng_ht *ht,
112 struct lttng_ht_node_str *node);
113LTTNG_HIDDEN
114void lttng_ht_add_unique_ulong(struct lttng_ht *ht,
115 struct lttng_ht_node_ulong *node);
116LTTNG_HIDDEN
117void lttng_ht_add_unique_u64(struct lttng_ht *ht,
118 struct lttng_ht_node_u64 *node);
119LTTNG_HIDDEN
120void lttng_ht_add_unique_two_u64(struct lttng_ht *ht,
121 struct lttng_ht_node_two_u64 *node);
122LTTNG_HIDDEN
123struct lttng_ht_node_ulong *lttng_ht_add_replace_ulong(
124 struct lttng_ht *ht, struct lttng_ht_node_ulong *node);
125LTTNG_HIDDEN
126struct lttng_ht_node_u64 *lttng_ht_add_replace_u64(
127 struct lttng_ht *ht, struct lttng_ht_node_u64 *node);
128LTTNG_HIDDEN
129void lttng_ht_add_str(struct lttng_ht *ht,
130 struct lttng_ht_node_str *node);
131LTTNG_HIDDEN
132void lttng_ht_add_ulong(struct lttng_ht *ht,
133 struct lttng_ht_node_ulong *node);
134LTTNG_HIDDEN
135void lttng_ht_add_u64(struct lttng_ht *ht,
136 struct lttng_ht_node_u64 *node);
137
138LTTNG_HIDDEN
139int lttng_ht_del(struct lttng_ht *ht, struct lttng_ht_iter *iter);
140
141LTTNG_HIDDEN
142void lttng_ht_get_first(struct lttng_ht *ht,
143 struct lttng_ht_iter *iter);
144LTTNG_HIDDEN
145void lttng_ht_get_next(struct lttng_ht *ht, struct lttng_ht_iter *iter);
146
147LTTNG_HIDDEN
148unsigned long lttng_ht_get_count(struct lttng_ht *ht);
149
150LTTNG_HIDDEN
151struct lttng_ht_node_str *lttng_ht_iter_get_node_str(
152 struct lttng_ht_iter *iter);
153LTTNG_HIDDEN
154struct lttng_ht_node_ulong *lttng_ht_iter_get_node_ulong(
155 struct lttng_ht_iter *iter);
156LTTNG_HIDDEN
157struct lttng_ht_node_u64 *lttng_ht_iter_get_node_u64(
158 struct lttng_ht_iter *iter);
159LTTNG_HIDDEN
160struct lttng_ht_node_two_u64 *lttng_ht_iter_get_node_two_u64(
161 struct lttng_ht_iter *iter);
162
163#endif /* _LTT_HT_H */
This page took 0.02241 seconds and 4 git commands to generate.