2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
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.
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
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.
24 #include "rculfhash.h"
25 #include "rculfhash-internal.h"
26 #include <common/macros.h>
28 extern unsigned long lttng_ht_seed
;
30 typedef unsigned long (*hash_fct
)(void *_key
, unsigned long seed
);
31 typedef cds_lfht_match_fct hash_match_fct
;
37 LTTNG_HT_TYPE_TWO_U64
,
42 cds_lfht_match_fct match_fct
;
46 struct lttng_ht_iter
{
47 struct cds_lfht_iter iter
;
50 struct lttng_ht_node_str
{
52 struct cds_lfht_node node
;
56 struct lttng_ht_node_ulong
{
58 struct cds_lfht_node node
;
62 struct lttng_ht_node_u64
{
64 struct cds_lfht_node node
;
68 struct lttng_ht_two_u64
{
73 struct lttng_ht_node_two_u64
{
74 struct lttng_ht_two_u64 key
;
75 struct cds_lfht_node node
;
79 /* Hashtable new and destroy */
81 struct lttng_ht
*lttng_ht_new(unsigned long size
, int type
);
83 void lttng_ht_destroy(struct lttng_ht
*ht
);
85 /* Specialized node init and free functions */
87 void lttng_ht_node_init_str(struct lttng_ht_node_str
*node
, char *key
);
89 void lttng_ht_node_init_ulong(struct lttng_ht_node_ulong
*node
,
92 void lttng_ht_node_init_u64(struct lttng_ht_node_u64
*node
,
95 void lttng_ht_node_init_two_u64(struct lttng_ht_node_two_u64
*node
,
96 uint64_t key1
, uint64_t key2
);
98 void lttng_ht_node_free_str(struct lttng_ht_node_str
*node
);
100 void lttng_ht_node_free_ulong(struct lttng_ht_node_ulong
*node
);
102 void lttng_ht_node_free_u64(struct lttng_ht_node_u64
*node
);
104 void lttng_ht_node_free_two_u64(struct lttng_ht_node_two_u64
*node
);
107 void lttng_ht_lookup(struct lttng_ht
*ht
, void *key
,
108 struct lttng_ht_iter
*iter
);
110 /* Specialized add unique functions */
112 void lttng_ht_add_unique_str(struct lttng_ht
*ht
,
113 struct lttng_ht_node_str
*node
);
115 void lttng_ht_add_unique_ulong(struct lttng_ht
*ht
,
116 struct lttng_ht_node_ulong
*node
);
118 void lttng_ht_add_unique_u64(struct lttng_ht
*ht
,
119 struct lttng_ht_node_u64
*node
);
121 void lttng_ht_add_unique_two_u64(struct lttng_ht
*ht
,
122 struct lttng_ht_node_two_u64
*node
);
124 struct lttng_ht_node_ulong
*lttng_ht_add_replace_ulong(
125 struct lttng_ht
*ht
, struct lttng_ht_node_ulong
*node
);
127 struct lttng_ht_node_u64
*lttng_ht_add_replace_u64(
128 struct lttng_ht
*ht
, struct lttng_ht_node_u64
*node
);
130 void lttng_ht_add_str(struct lttng_ht
*ht
,
131 struct lttng_ht_node_str
*node
);
133 void lttng_ht_add_ulong(struct lttng_ht
*ht
,
134 struct lttng_ht_node_ulong
*node
);
136 void lttng_ht_add_u64(struct lttng_ht
*ht
,
137 struct lttng_ht_node_u64
*node
);
140 int lttng_ht_del(struct lttng_ht
*ht
, struct lttng_ht_iter
*iter
);
143 void lttng_ht_get_first(struct lttng_ht
*ht
,
144 struct lttng_ht_iter
*iter
);
146 void lttng_ht_get_next(struct lttng_ht
*ht
, struct lttng_ht_iter
*iter
);
149 unsigned long lttng_ht_get_count(struct lttng_ht
*ht
);
152 struct lttng_ht_node_str
*lttng_ht_iter_get_node_str(
153 struct lttng_ht_iter
*iter
);
155 struct lttng_ht_node_ulong
*lttng_ht_iter_get_node_ulong(
156 struct lttng_ht_iter
*iter
);
158 struct lttng_ht_node_u64
*lttng_ht_iter_get_node_u64(
159 struct lttng_ht_iter
*iter
);
161 struct lttng_ht_node_two_u64
*lttng_ht_iter_get_node_two_u64(
162 struct lttng_ht_iter
*iter
);
164 #endif /* _LTT_HT_H */