Commit | Line | Data |
---|---|---|
bec39940 | 1 | /* |
ab5be9fa | 2 | * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca> |
bec39940 | 3 | * |
ab5be9fa | 4 | * SPDX-License-Identifier: GPL-2.0-only |
bec39940 | 5 | * |
bec39940 DG |
6 | */ |
7 | ||
8 | #ifndef _LTT_HT_H | |
9 | #define _LTT_HT_H | |
10 | ||
11 | #include <urcu.h> | |
d88aee68 | 12 | #include <stdint.h> |
10a8a223 | 13 | |
d604af56 | 14 | #include <common/macros.h> |
8684af09 | 15 | #include <urcu/rculfhash.h> |
bec39940 | 16 | |
7966af57 SM |
17 | #ifdef __cplusplus |
18 | extern "C" { | |
19 | #endif | |
20 | ||
b6314938 DG |
21 | extern unsigned long lttng_ht_seed; |
22 | ||
7966af57 | 23 | typedef unsigned long (*hash_fct_type)(const void *_key, unsigned long seed); |
bec39940 DG |
24 | typedef cds_lfht_match_fct hash_match_fct; |
25 | ||
26 | enum lttng_ht_type { | |
27 | LTTNG_HT_TYPE_STRING, | |
28 | LTTNG_HT_TYPE_ULONG, | |
d88aee68 | 29 | LTTNG_HT_TYPE_U64, |
3c4599b9 | 30 | LTTNG_HT_TYPE_TWO_U64, |
bec39940 DG |
31 | }; |
32 | ||
33 | struct lttng_ht { | |
34 | struct cds_lfht *ht; | |
35 | cds_lfht_match_fct match_fct; | |
7966af57 | 36 | hash_fct_type hash_fct; |
bec39940 DG |
37 | }; |
38 | ||
39 | struct lttng_ht_iter { | |
40 | struct cds_lfht_iter iter; | |
41 | }; | |
42 | ||
43 | struct lttng_ht_node_str { | |
44 | char *key; | |
45 | struct cds_lfht_node node; | |
46 | struct rcu_head head; | |
47 | }; | |
48 | ||
49 | struct lttng_ht_node_ulong { | |
50 | unsigned long key; | |
51 | struct cds_lfht_node node; | |
52 | struct rcu_head head; | |
53 | }; | |
54 | ||
d88aee68 DG |
55 | struct lttng_ht_node_u64 { |
56 | uint64_t key; | |
57 | struct cds_lfht_node node; | |
58 | struct rcu_head head; | |
59 | }; | |
60 | ||
3c4599b9 JD |
61 | struct lttng_ht_two_u64 { |
62 | uint64_t key1; | |
63 | uint64_t key2; | |
64 | }; | |
65 | ||
66 | struct lttng_ht_node_two_u64 { | |
67 | struct lttng_ht_two_u64 key; | |
68 | struct cds_lfht_node node; | |
69 | struct rcu_head head; | |
70 | }; | |
71 | ||
bec39940 | 72 | /* Hashtable new and destroy */ |
d604af56 | 73 | struct lttng_ht *lttng_ht_new(unsigned long size, int type); |
d604af56 | 74 | void lttng_ht_destroy(struct lttng_ht *ht); |
bec39940 DG |
75 | |
76 | /* Specialized node init and free functions */ | |
d604af56 | 77 | void lttng_ht_node_init_str(struct lttng_ht_node_str *node, char *key); |
d604af56 | 78 | void lttng_ht_node_init_ulong(struct lttng_ht_node_ulong *node, |
bec39940 | 79 | unsigned long key); |
d604af56 | 80 | void lttng_ht_node_init_u64(struct lttng_ht_node_u64 *node, |
d88aee68 | 81 | uint64_t key); |
d604af56 | 82 | void lttng_ht_node_init_two_u64(struct lttng_ht_node_two_u64 *node, |
3c4599b9 | 83 | uint64_t key1, uint64_t key2); |
d604af56 | 84 | void lttng_ht_node_free_str(struct lttng_ht_node_str *node); |
d604af56 | 85 | void lttng_ht_node_free_ulong(struct lttng_ht_node_ulong *node); |
d604af56 | 86 | void lttng_ht_node_free_u64(struct lttng_ht_node_u64 *node); |
d604af56 JG |
87 | void lttng_ht_node_free_two_u64(struct lttng_ht_node_two_u64 *node); |
88 | ||
fb9a95c4 | 89 | void lttng_ht_lookup(struct lttng_ht *ht, const void *key, |
bec39940 DG |
90 | struct lttng_ht_iter *iter); |
91 | ||
92 | /* Specialized add unique functions */ | |
d604af56 | 93 | void lttng_ht_add_unique_str(struct lttng_ht *ht, |
bec39940 | 94 | struct lttng_ht_node_str *node); |
d604af56 | 95 | void lttng_ht_add_unique_ulong(struct lttng_ht *ht, |
bec39940 | 96 | struct lttng_ht_node_ulong *node); |
d604af56 | 97 | void lttng_ht_add_unique_u64(struct lttng_ht *ht, |
d88aee68 | 98 | struct lttng_ht_node_u64 *node); |
d604af56 | 99 | void lttng_ht_add_unique_two_u64(struct lttng_ht *ht, |
3c4599b9 | 100 | struct lttng_ht_node_two_u64 *node); |
d604af56 | 101 | struct lttng_ht_node_ulong *lttng_ht_add_replace_ulong( |
852d0037 | 102 | struct lttng_ht *ht, struct lttng_ht_node_ulong *node); |
d604af56 | 103 | struct lttng_ht_node_u64 *lttng_ht_add_replace_u64( |
d88aee68 | 104 | struct lttng_ht *ht, struct lttng_ht_node_u64 *node); |
d604af56 | 105 | void lttng_ht_add_str(struct lttng_ht *ht, |
efa116c6 | 106 | struct lttng_ht_node_str *node); |
d604af56 | 107 | void lttng_ht_add_ulong(struct lttng_ht *ht, |
aefea3b7 | 108 | struct lttng_ht_node_ulong *node); |
d604af56 | 109 | void lttng_ht_add_u64(struct lttng_ht *ht, |
d88aee68 | 110 | struct lttng_ht_node_u64 *node); |
bec39940 | 111 | |
d604af56 | 112 | int lttng_ht_del(struct lttng_ht *ht, struct lttng_ht_iter *iter); |
bec39940 | 113 | |
d604af56 | 114 | void lttng_ht_get_first(struct lttng_ht *ht, |
bec39940 | 115 | struct lttng_ht_iter *iter); |
d604af56 | 116 | void lttng_ht_get_next(struct lttng_ht *ht, struct lttng_ht_iter *iter); |
bec39940 | 117 | |
d604af56 | 118 | unsigned long lttng_ht_get_count(struct lttng_ht *ht); |
bec39940 | 119 | |
d604af56 | 120 | struct lttng_ht_node_str *lttng_ht_iter_get_node_str( |
bec39940 | 121 | struct lttng_ht_iter *iter); |
d604af56 | 122 | struct lttng_ht_node_ulong *lttng_ht_iter_get_node_ulong( |
bec39940 | 123 | struct lttng_ht_iter *iter); |
d604af56 | 124 | struct lttng_ht_node_u64 *lttng_ht_iter_get_node_u64( |
d88aee68 | 125 | struct lttng_ht_iter *iter); |
d604af56 | 126 | struct lttng_ht_node_two_u64 *lttng_ht_iter_get_node_two_u64( |
3c4599b9 | 127 | struct lttng_ht_iter *iter); |
bec39940 | 128 | |
7966af57 SM |
129 | #ifdef __cplusplus |
130 | } | |
131 | #endif | |
132 | ||
bec39940 | 133 | #endif /* _LTT_HT_H */ |