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 <common/macros.h>
25 #include <urcu/rculfhash.h>
27 extern unsigned long lttng_ht_seed
;
29 typedef unsigned long (*hash_fct
)(const void *_key
, unsigned long seed
);
30 typedef cds_lfht_match_fct hash_match_fct
;
36 LTTNG_HT_TYPE_TWO_U64
,
41 cds_lfht_match_fct match_fct
;
45 struct lttng_ht_iter
{
46 struct cds_lfht_iter iter
;
49 struct lttng_ht_node_str
{
51 struct cds_lfht_node node
;
55 struct lttng_ht_node_ulong
{
57 struct cds_lfht_node node
;
61 struct lttng_ht_node_u64
{
63 struct cds_lfht_node node
;
67 struct lttng_ht_two_u64
{
72 struct lttng_ht_node_two_u64
{
73 struct lttng_ht_two_u64 key
;
74 struct cds_lfht_node node
;
78 /* Hashtable new and destroy */
80 struct lttng_ht
*lttng_ht_new(unsigned long size
, int type
);
82 void lttng_ht_destroy(struct lttng_ht
*ht
);
84 /* Specialized node init and free functions */
86 void lttng_ht_node_init_str(struct lttng_ht_node_str
*node
, char *key
);
88 void lttng_ht_node_init_ulong(struct lttng_ht_node_ulong
*node
,
91 void lttng_ht_node_init_u64(struct lttng_ht_node_u64
*node
,
94 void lttng_ht_node_init_two_u64(struct lttng_ht_node_two_u64
*node
,
95 uint64_t key1
, uint64_t key2
);
97 void lttng_ht_node_free_str(struct lttng_ht_node_str
*node
);
99 void lttng_ht_node_free_ulong(struct lttng_ht_node_ulong
*node
);
101 void lttng_ht_node_free_u64(struct lttng_ht_node_u64
*node
);
103 void lttng_ht_node_free_two_u64(struct lttng_ht_node_two_u64
*node
);
106 void lttng_ht_lookup(struct lttng_ht
*ht
, void *key
,
107 struct lttng_ht_iter
*iter
);
109 /* Specialized add unique functions */
111 void lttng_ht_add_unique_str(struct lttng_ht
*ht
,
112 struct lttng_ht_node_str
*node
);
114 void lttng_ht_add_unique_ulong(struct lttng_ht
*ht
,
115 struct lttng_ht_node_ulong
*node
);
117 void lttng_ht_add_unique_u64(struct lttng_ht
*ht
,
118 struct lttng_ht_node_u64
*node
);
120 void lttng_ht_add_unique_two_u64(struct lttng_ht
*ht
,
121 struct lttng_ht_node_two_u64
*node
);
123 struct lttng_ht_node_ulong
*lttng_ht_add_replace_ulong(
124 struct lttng_ht
*ht
, struct lttng_ht_node_ulong
*node
);
126 struct lttng_ht_node_u64
*lttng_ht_add_replace_u64(
127 struct lttng_ht
*ht
, struct lttng_ht_node_u64
*node
);
129 void lttng_ht_add_str(struct lttng_ht
*ht
,
130 struct lttng_ht_node_str
*node
);
132 void lttng_ht_add_ulong(struct lttng_ht
*ht
,
133 struct lttng_ht_node_ulong
*node
);
135 void lttng_ht_add_u64(struct lttng_ht
*ht
,
136 struct lttng_ht_node_u64
*node
);
139 int lttng_ht_del(struct lttng_ht
*ht
, struct lttng_ht_iter
*iter
);
142 void lttng_ht_get_first(struct lttng_ht
*ht
,
143 struct lttng_ht_iter
*iter
);
145 void lttng_ht_get_next(struct lttng_ht
*ht
, struct lttng_ht_iter
*iter
);
148 unsigned long lttng_ht_get_count(struct lttng_ht
*ht
);
151 struct lttng_ht_node_str
*lttng_ht_iter_get_node_str(
152 struct lttng_ht_iter
*iter
);
154 struct lttng_ht_node_ulong
*lttng_ht_iter_get_node_ulong(
155 struct lttng_ht_iter
*iter
);
157 struct lttng_ht_node_u64
*lttng_ht_iter_get_node_u64(
158 struct lttng_ht_iter
*iter
);
160 struct lttng_ht_node_two_u64
*lttng_ht_iter_get_node_two_u64(
161 struct lttng_ht_iter
*iter
);
163 #endif /* _LTT_HT_H */