Relicence all source and header files included in LGPL code
[lttng-tools.git] / src / common / hashtable / hashtable.h
CommitLineData
bec39940 1/*
21cf9b6b 2 * Copyright (C) 2011 EfficiOS Inc.
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>
4bd69c5f 15#include <lttng/lttng-export.h>
8684af09 16#include <urcu/rculfhash.h>
bec39940 17
4bd69c5f 18LTTNG_EXPORT extern unsigned long lttng_ht_seed;
b6314938 19
7966af57 20typedef unsigned long (*hash_fct_type)(const void *_key, unsigned long seed);
bec39940
DG
21typedef cds_lfht_match_fct hash_match_fct;
22
23enum lttng_ht_type {
24 LTTNG_HT_TYPE_STRING,
25 LTTNG_HT_TYPE_ULONG,
d88aee68 26 LTTNG_HT_TYPE_U64,
3c4599b9 27 LTTNG_HT_TYPE_TWO_U64,
bec39940
DG
28};
29
30struct lttng_ht {
31 struct cds_lfht *ht;
32 cds_lfht_match_fct match_fct;
7966af57 33 hash_fct_type hash_fct;
bec39940
DG
34};
35
36struct lttng_ht_iter {
37 struct cds_lfht_iter iter;
38};
39
40struct lttng_ht_node_str {
41 char *key;
42 struct cds_lfht_node node;
43 struct rcu_head head;
44};
45
46struct lttng_ht_node_ulong {
47 unsigned long key;
48 struct cds_lfht_node node;
49 struct rcu_head head;
50};
51
d88aee68
DG
52struct lttng_ht_node_u64 {
53 uint64_t key;
54 struct cds_lfht_node node;
55 struct rcu_head head;
56};
57
3c4599b9
JD
58struct lttng_ht_two_u64 {
59 uint64_t key1;
60 uint64_t key2;
61};
62
63struct lttng_ht_node_two_u64 {
64 struct lttng_ht_two_u64 key;
65 struct cds_lfht_node node;
66 struct rcu_head head;
67};
68
bec39940 69/* Hashtable new and destroy */
6dca8ba7 70struct lttng_ht *lttng_ht_new(unsigned long size, enum lttng_ht_type type);
d604af56 71void lttng_ht_destroy(struct lttng_ht *ht);
bec39940
DG
72
73/* Specialized node init and free functions */
d604af56 74void lttng_ht_node_init_str(struct lttng_ht_node_str *node, char *key);
d604af56 75void lttng_ht_node_init_ulong(struct lttng_ht_node_ulong *node,
bec39940 76 unsigned long key);
d604af56 77void lttng_ht_node_init_u64(struct lttng_ht_node_u64 *node,
d88aee68 78 uint64_t key);
d604af56 79void lttng_ht_node_init_two_u64(struct lttng_ht_node_two_u64 *node,
3c4599b9 80 uint64_t key1, uint64_t key2);
d604af56 81void lttng_ht_node_free_str(struct lttng_ht_node_str *node);
d604af56 82void lttng_ht_node_free_ulong(struct lttng_ht_node_ulong *node);
d604af56 83void lttng_ht_node_free_u64(struct lttng_ht_node_u64 *node);
d604af56
JG
84void lttng_ht_node_free_two_u64(struct lttng_ht_node_two_u64 *node);
85
fb9a95c4 86void lttng_ht_lookup(struct lttng_ht *ht, const void *key,
bec39940
DG
87 struct lttng_ht_iter *iter);
88
89/* Specialized add unique functions */
d604af56 90void lttng_ht_add_unique_str(struct lttng_ht *ht,
bec39940 91 struct lttng_ht_node_str *node);
d604af56 92void lttng_ht_add_unique_ulong(struct lttng_ht *ht,
bec39940 93 struct lttng_ht_node_ulong *node);
d604af56 94void lttng_ht_add_unique_u64(struct lttng_ht *ht,
d88aee68 95 struct lttng_ht_node_u64 *node);
d604af56 96void lttng_ht_add_unique_two_u64(struct lttng_ht *ht,
3c4599b9 97 struct lttng_ht_node_two_u64 *node);
d604af56 98struct lttng_ht_node_ulong *lttng_ht_add_replace_ulong(
852d0037 99 struct lttng_ht *ht, struct lttng_ht_node_ulong *node);
d604af56 100struct lttng_ht_node_u64 *lttng_ht_add_replace_u64(
d88aee68 101 struct lttng_ht *ht, struct lttng_ht_node_u64 *node);
d604af56 102void lttng_ht_add_str(struct lttng_ht *ht,
efa116c6 103 struct lttng_ht_node_str *node);
d604af56 104void lttng_ht_add_ulong(struct lttng_ht *ht,
aefea3b7 105 struct lttng_ht_node_ulong *node);
d604af56 106void lttng_ht_add_u64(struct lttng_ht *ht,
d88aee68 107 struct lttng_ht_node_u64 *node);
bec39940 108
d604af56 109int lttng_ht_del(struct lttng_ht *ht, struct lttng_ht_iter *iter);
bec39940 110
d604af56 111void lttng_ht_get_first(struct lttng_ht *ht,
bec39940 112 struct lttng_ht_iter *iter);
d604af56 113void lttng_ht_get_next(struct lttng_ht *ht, struct lttng_ht_iter *iter);
bec39940 114
d604af56 115unsigned long lttng_ht_get_count(struct lttng_ht *ht);
bec39940 116
d604af56 117struct lttng_ht_node_str *lttng_ht_iter_get_node_str(
bec39940 118 struct lttng_ht_iter *iter);
d604af56 119struct lttng_ht_node_ulong *lttng_ht_iter_get_node_ulong(
bec39940 120 struct lttng_ht_iter *iter);
d604af56 121struct lttng_ht_node_u64 *lttng_ht_iter_get_node_u64(
d88aee68 122 struct lttng_ht_iter *iter);
d604af56 123struct lttng_ht_node_two_u64 *lttng_ht_iter_get_node_two_u64(
3c4599b9 124 struct lttng_ht_iter *iter);
bec39940
DG
125
126#endif /* _LTT_HT_H */
This page took 0.068401 seconds and 4 git commands to generate.