4a8a2bd5c53a184b40ebe5484213816934a80300
[lttng-tools.git] / src / common / hashtable / hashtable.h
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 "rculfhash.h"
25 #include "rculfhash-internal.h"
26
27 extern unsigned long lttng_ht_seed;
28
29 typedef unsigned long (*hash_fct)(void *_key, unsigned long seed);
30 typedef cds_lfht_match_fct hash_match_fct;
31
32 enum lttng_ht_type {
33 LTTNG_HT_TYPE_STRING,
34 LTTNG_HT_TYPE_ULONG,
35 LTTNG_HT_TYPE_U64,
36 };
37
38 struct lttng_ht {
39 struct cds_lfht *ht;
40 cds_lfht_match_fct match_fct;
41 hash_fct hash_fct;
42 };
43
44 struct lttng_ht_iter {
45 struct cds_lfht_iter iter;
46 };
47
48 struct lttng_ht_node_str {
49 char *key;
50 struct cds_lfht_node node;
51 struct rcu_head head;
52 };
53
54 struct lttng_ht_node_ulong {
55 unsigned long key;
56 struct cds_lfht_node node;
57 struct rcu_head head;
58 };
59
60 struct lttng_ht_node_u64 {
61 uint64_t key;
62 struct cds_lfht_node node;
63 struct rcu_head head;
64 };
65
66 /* Hashtable new and destroy */
67 extern struct lttng_ht *lttng_ht_new(unsigned long size, int type);
68 extern void lttng_ht_destroy(struct lttng_ht *ht);
69
70 /* Specialized node init and free functions */
71 extern void lttng_ht_node_init_str(struct lttng_ht_node_str *node, char *key);
72 extern void lttng_ht_node_init_ulong(struct lttng_ht_node_ulong *node,
73 unsigned long key);
74 extern void lttng_ht_node_init_u64(struct lttng_ht_node_u64 *node,
75 uint64_t key);
76 extern void lttng_ht_node_free_str(struct lttng_ht_node_str *node);
77 extern void lttng_ht_node_free_ulong(struct lttng_ht_node_ulong *node);
78 extern void lttng_ht_node_free_u64(struct lttng_ht_node_u64 *node);
79
80 extern void lttng_ht_lookup(struct lttng_ht *ht, void *key,
81 struct lttng_ht_iter *iter);
82
83 /* Specialized add unique functions */
84 extern void lttng_ht_add_unique_str(struct lttng_ht *ht,
85 struct lttng_ht_node_str *node);
86 extern void lttng_ht_add_unique_ulong(struct lttng_ht *ht,
87 struct lttng_ht_node_ulong *node);
88 extern void lttng_ht_add_unique_u64(struct lttng_ht *ht,
89 struct lttng_ht_node_u64 *node);
90 extern struct lttng_ht_node_ulong *lttng_ht_add_replace_ulong(
91 struct lttng_ht *ht, struct lttng_ht_node_ulong *node);
92 extern struct lttng_ht_node_u64 *lttng_ht_add_replace_u64(
93 struct lttng_ht *ht, struct lttng_ht_node_u64 *node);
94 extern void lttng_ht_add_str(struct lttng_ht *ht,
95 struct lttng_ht_node_str *node);
96 extern void lttng_ht_add_ulong(struct lttng_ht *ht,
97 struct lttng_ht_node_ulong *node);
98 extern void lttng_ht_add_u64(struct lttng_ht *ht,
99 struct lttng_ht_node_u64 *node);
100
101 extern int lttng_ht_del(struct lttng_ht *ht, struct lttng_ht_iter *iter);
102
103 extern void lttng_ht_get_first(struct lttng_ht *ht,
104 struct lttng_ht_iter *iter);
105 extern void lttng_ht_get_next(struct lttng_ht *ht, struct lttng_ht_iter *iter);
106
107 extern unsigned long lttng_ht_get_count(struct lttng_ht *ht);
108
109 extern struct lttng_ht_node_str *lttng_ht_iter_get_node_str(
110 struct lttng_ht_iter *iter);
111 extern struct lttng_ht_node_ulong *lttng_ht_iter_get_node_ulong(
112 struct lttng_ht_iter *iter);
113 extern struct lttng_ht_node_u64 *lttng_ht_iter_get_node_u64(
114 struct lttng_ht_iter *iter);
115
116 #endif /* _LTT_HT_H */
This page took 0.044363 seconds and 3 git commands to generate.