Comment out dictionary with hashtable code for now (#18814)
Stelios Fragkakis committed
Oct 18, 2024 at 21:33 UTC
fe153fc47b746fa1813d5964596cb0d81fe807b0
3 files changed
+127
-121
src/libnetdata/dictionary/dictionary-hashtable.h
+124
-118
@@ -8,96 +8,96 @@
8
// ----------------------------------------------------------------------------
9
// hashtable operations with simple hashtable
10
11
-static inline bool compare_keys(void *key1, void *key2) {
12
- const char *k1 = key1;
13
- const char *k2 = key2;
14
- return strcmp(k1, k2) == 0;
15
-}
16
-
17
-static inline void *item_to_key(DICTIONARY_ITEM *item) {
18
- return (void *)item_get_name(item);
19
-}
20
-
21
-#define SIMPLE_HASHTABLE_VALUE_TYPE DICTIONARY_ITEM
22
-#define SIMPLE_HASHTABLE_NAME _DICTIONARY
23
-#define SIMPLE_HASHTABLE_VALUE2KEY_FUNCTION item_to_key
24
-#define SIMPLE_HASHTABLE_COMPARE_KEYS_FUNCTION compare_keys
25
-#include "..//simple_hashtable.h"
26
-
27
-static inline size_t hashtable_init_hashtable(DICTIONARY *dict) {
28
- SIMPLE_HASHTABLE_DICTIONARY *ht = callocz(1, sizeof(*ht));
29
- simple_hashtable_init_DICTIONARY(ht, 4);
30
- dict->index.JudyHSArray = ht;
31
- return 0;
32
-}
33
-
34
-static inline size_t hashtable_destroy_hashtable(DICTIONARY *dict) {
35
- SIMPLE_HASHTABLE_DICTIONARY *ht = dict->index.JudyHSArray;
36
- if(unlikely(!ht)) return 0;
37
-
38
- size_t mem = sizeof(*ht) + ht->size * sizeof(SIMPLE_HASHTABLE_SLOT_DICTIONARY);
39
- simple_hashtable_destroy_DICTIONARY(ht);
40
- freez(ht);
41
- dict->index.JudyHSArray = NULL;
42
-
43
- return mem;
44
-}
45
-
46
-static inline void *hashtable_insert_hashtable(DICTIONARY *dict, const char *name, size_t name_len) {
47
- SIMPLE_HASHTABLE_DICTIONARY *ht = dict->index.JudyHSArray;
48
-
49
- char key[name_len+1];
50
- memcpy(key, name, name_len);
51
- key[name_len] = '\0';
52
-
53
- XXH64_hash_t hash = XXH3_64bits(name, name_len);
54
- SIMPLE_HASHTABLE_SLOT_DICTIONARY *sl = simple_hashtable_get_slot_DICTIONARY(ht, hash, key, true);
55
- sl->hash = hash; // we will need it in insert later - it is ok to overwrite - it is the same already
56
- return sl;
57
-}
58
-
59
-static inline DICTIONARY_ITEM *hashtable_insert_handle_to_item_hashtable(DICTIONARY *dict, void *handle) {
60
- (void)dict;
61
- SIMPLE_HASHTABLE_SLOT_DICTIONARY *sl = handle;
62
- DICTIONARY_ITEM *item = SIMPLE_HASHTABLE_SLOT_DATA(sl);
63
- return item;
64
-}
65
-
66
-static inline void hashtable_set_item_hashtable(DICTIONARY *dict, void *handle, DICTIONARY_ITEM *item) {
67
- SIMPLE_HASHTABLE_DICTIONARY *ht = dict->index.JudyHSArray;
68
- SIMPLE_HASHTABLE_SLOT_DICTIONARY *sl = handle;
69
- simple_hashtable_set_slot_DICTIONARY(ht, sl, sl->hash, item);
70
-}
71
-
72
-static inline int hashtable_delete_hashtable(DICTIONARY *dict, const char *name, size_t name_len, DICTIONARY_ITEM *item_to_delete) {
73
- (void)item_to_delete;
74
- SIMPLE_HASHTABLE_DICTIONARY *ht = dict->index.JudyHSArray;
75
-
76
- char key[name_len+1];
77
- memcpy(key, name, name_len);
78
- key[name_len] = '\0';
79
-
80
- XXH64_hash_t hash = XXH3_64bits(name, name_len);
81
- SIMPLE_HASHTABLE_SLOT_DICTIONARY *sl = simple_hashtable_get_slot_DICTIONARY(ht, hash, key, false);
82
- DICTIONARY_ITEM *item = SIMPLE_HASHTABLE_SLOT_DATA(sl);
83
- if(!item) return 0; // return not-found
84
-
85
- simple_hashtable_del_slot_DICTIONARY(ht, sl);
86
- return 1; // return deleted
87
-}
88
-
89
-static inline DICTIONARY_ITEM *hashtable_get_hashtable(DICTIONARY *dict, const char *name, size_t name_len) {
90
- SIMPLE_HASHTABLE_DICTIONARY *ht = dict->index.JudyHSArray;
91
- if(unlikely(!ht)) return NULL;
92
-
93
- char key[name_len+1];
94
- memcpy(key, name, name_len);
95
- key[name_len] = '\0';
96
-
97
- XXH64_hash_t hash = XXH3_64bits(name, name_len);
98
- SIMPLE_HASHTABLE_SLOT_DICTIONARY *sl = simple_hashtable_get_slot_DICTIONARY(ht, hash, key, true);
99
- return SIMPLE_HASHTABLE_SLOT_DATA(sl);
100
-}
11
+//static inline bool compare_keys(void *key1, void *key2) {
12
+// const char *k1 = key1;
13
+// const char *k2 = key2;
14
+// return strcmp(k1, k2) == 0;
15
+//}
16
+//
17
+//static inline void *item_to_key(DICTIONARY_ITEM *item) {
18
+// return (void *)item_get_name(item);
19
+//}
20
+//
21
+//#define SIMPLE_HASHTABLE_VALUE_TYPE DICTIONARY_ITEM
22
+//#define SIMPLE_HASHTABLE_NAME _DICTIONARY
23
+//#define SIMPLE_HASHTABLE_VALUE2KEY_FUNCTION item_to_key
24
+//#define SIMPLE_HASHTABLE_COMPARE_KEYS_FUNCTION compare_keys
25
+//#include "..//simple_hashtable.h"
26
+
27
+//static inline size_t hashtable_init_hashtable(DICTIONARY *dict) {
28
+// SIMPLE_HASHTABLE_DICTIONARY *ht = callocz(1, sizeof(*ht));
29
+// simple_hashtable_init_DICTIONARY(ht, 4);
30
+// dict->index.JudyHSArray = ht;
31
+// return 0;
32
+//}
33
+//
34
+//static inline size_t hashtable_destroy_hashtable(DICTIONARY *dict) {
35
+// SIMPLE_HASHTABLE_DICTIONARY *ht = dict->index.JudyHSArray;
36
+// if(unlikely(!ht)) return 0;
37
+//
38
+// size_t mem = sizeof(*ht) + ht->size * sizeof(SIMPLE_HASHTABLE_SLOT_DICTIONARY);
39
+// simple_hashtable_destroy_DICTIONARY(ht);
40
+// freez(ht);
41
+// dict->index.JudyHSArray = NULL;
42
+//
43
+// return mem;
44
+//}
45
+//
46
+//static inline void *hashtable_insert_hashtable(DICTIONARY *dict, const char *name, size_t name_len) {
47
+// SIMPLE_HASHTABLE_DICTIONARY *ht = dict->index.JudyHSArray;
48
+//
49
+// char key[name_len+1];
50
+// memcpy(key, name, name_len);
51
+// key[name_len] = '\0';
52
+//
53
+// XXH64_hash_t hash = XXH3_64bits(name, name_len);
54
+// SIMPLE_HASHTABLE_SLOT_DICTIONARY *sl = simple_hashtable_get_slot_DICTIONARY(ht, hash, key, true);
55
+// sl->hash = hash; // we will need it in insert later - it is ok to overwrite - it is the same already
56
+// return sl;
57
+//}
58
+//
59
+//static inline DICTIONARY_ITEM *hashtable_insert_handle_to_item_hashtable(DICTIONARY *dict, void *handle) {
60
+// (void)dict;
61
+// SIMPLE_HASHTABLE_SLOT_DICTIONARY *sl = handle;
62
+// DICTIONARY_ITEM *item = SIMPLE_HASHTABLE_SLOT_DATA(sl);
63
+// return item;
64
+//}
65
+//
66
+//static inline void hashtable_set_item_hashtable(DICTIONARY *dict, void *handle, DICTIONARY_ITEM *item) {
67
+// SIMPLE_HASHTABLE_DICTIONARY *ht = dict->index.JudyHSArray;
68
+// SIMPLE_HASHTABLE_SLOT_DICTIONARY *sl = handle;
69
+// simple_hashtable_set_slot_DICTIONARY(ht, sl, sl->hash, item);
70
+//}
71
+//
72
+//static inline int hashtable_delete_hashtable(DICTIONARY *dict, const char *name, size_t name_len, DICTIONARY_ITEM *item_to_delete) {
73
+// (void)item_to_delete;
74
+// SIMPLE_HASHTABLE_DICTIONARY *ht = dict->index.JudyHSArray;
75
+//
76
+// char key[name_len+1];
77
+// memcpy(key, name, name_len);
78
+// key[name_len] = '\0';
79
+//
80
+// XXH64_hash_t hash = XXH3_64bits(name, name_len);
81
+// SIMPLE_HASHTABLE_SLOT_DICTIONARY *sl = simple_hashtable_get_slot_DICTIONARY(ht, hash, key, false);
82
+// DICTIONARY_ITEM *item = SIMPLE_HASHTABLE_SLOT_DATA(sl);
83
+// if(!item) return 0; // return not-found
84
+//
85
+// simple_hashtable_del_slot_DICTIONARY(ht, sl);
86
+// return 1; // return deleted
87
+//}
88
+//
89
+//static inline DICTIONARY_ITEM *hashtable_get_hashtable(DICTIONARY *dict, const char *name, size_t name_len) {
90
+// SIMPLE_HASHTABLE_DICTIONARY *ht = dict->index.JudyHSArray;
91
+// if(unlikely(!ht)) return NULL;
92
+//
93
+// char key[name_len+1];
94
+// memcpy(key, name, name_len);
95
+// key[name_len] = '\0';
96
+//
97
+// XXH64_hash_t hash = XXH3_64bits(name, name_len);
98
+// SIMPLE_HASHTABLE_SLOT_DICTIONARY *sl = simple_hashtable_get_slot_DICTIONARY(ht, hash, key, true);
99
+// return SIMPLE_HASHTABLE_SLOT_DATA(sl);
100
+//}
101
102
// ----------------------------------------------------------------------------
103
// hashtable operations with Judy
@@ -201,40 +201,44 @@ static inline DICTIONARY_ITEM *hashtable_get_judy(DICTIONARY *dict, const char *
201
// select the right hashtable
202
203
static inline size_t hashtable_init_unsafe(DICTIONARY *dict) {
204
- if(dict->options & DICT_OPTION_INDEX_JUDY)
205
- return hashtable_init_judy(dict);
206
- else
207
- return hashtable_init_hashtable(dict);
204
+ return hashtable_init_judy(dict);
205
+// if(dict->options & DICT_OPTION_INDEX_JUDY)
206
+// return hashtable_init_judy(dict);
207
+// else
208
+// return hashtable_init_hashtable(dict);
209
}
210
211
static inline size_t hashtable_destroy_unsafe(DICTIONARY *dict) {
212
pointer_destroy_index(dict);
213
213
- if(dict->options & DICT_OPTION_INDEX_JUDY)
214
- return hashtable_destroy_judy(dict);
215
- else
216
- return hashtable_destroy_hashtable(dict);
214
+// if(dict->options & DICT_OPTION_INDEX_JUDY)
215
+ return hashtable_destroy_judy(dict);
216
+// else
217
+// return hashtable_destroy_hashtable(dict);
218
}
219
220
static inline void *hashtable_insert_unsafe(DICTIONARY *dict, const char *name, size_t name_len) {
220
- if(dict->options & DICT_OPTION_INDEX_JUDY)
221
- return hashtable_insert_judy(dict, name, name_len);
222
- else
223
- return hashtable_insert_hashtable(dict, name, name_len);
221
+ return hashtable_insert_judy(dict, name, name_len);
222
+// if(dict->options & DICT_OPTION_INDEX_JUDY)
223
+// return hashtable_insert_judy(dict, name, name_len);
224
+// else
225
+// return hashtable_insert_hashtable(dict, name, name_len);
226
}
227
228
static inline DICTIONARY_ITEM *hashtable_insert_handle_to_item_unsafe(DICTIONARY *dict, void *handle) {
227
- if(dict->options & DICT_OPTION_INDEX_JUDY)
228
- return hashtable_insert_handle_to_item_judy(dict, handle);
229
- else
230
- return hashtable_insert_handle_to_item_hashtable(dict, handle);
229
+ return hashtable_insert_handle_to_item_judy(dict, handle);
230
+// if(dict->options & DICT_OPTION_INDEX_JUDY)
231
+// return hashtable_insert_handle_to_item_judy(dict, handle);
232
+// else
233
+// return hashtable_insert_handle_to_item_hashtable(dict, handle);
234
}
235
236
static inline int hashtable_delete_unsafe(DICTIONARY *dict, const char *name, size_t name_len, DICTIONARY_ITEM *item) {
234
- if(dict->options & DICT_OPTION_INDEX_JUDY)
235
- return hashtable_delete_judy(dict, name, name_len, item);
236
- else
237
- return hashtable_delete_hashtable(dict, name, name_len, item);
237
+ return hashtable_delete_judy(dict, name, name_len, item);
238
+// if(dict->options & DICT_OPTION_INDEX_JUDY)
239
+// return hashtable_delete_judy(dict, name, name_len, item);
240
+// else
241
+// return hashtable_delete_hashtable(dict, name, name_len, item);
242
}
243
244
static inline DICTIONARY_ITEM *hashtable_get_unsafe(DICTIONARY *dict, const char *name, size_t name_len) {
@@ -242,10 +246,11 @@ static inline DICTIONARY_ITEM *hashtable_get_unsafe(DICTIONARY *dict, const char
246
247
DICTIONARY_ITEM *item;
248
245
- if(dict->options & DICT_OPTION_INDEX_JUDY)
246
- item = hashtable_get_judy(dict, name, name_len);
247
- else
248
- item = hashtable_get_hashtable(dict, name, name_len);
249
+ item = hashtable_get_judy(dict, name, name_len);
250
+// if(dict->options & DICT_OPTION_INDEX_JUDY)
251
+// item = hashtable_get_judy(dict, name, name_len);
252
+// else
253
+// item = hashtable_get_hashtable(dict, name, name_len);
254
255
if(item)
256
pointer_check(dict, item);
@@ -254,10 +259,11 @@ static inline DICTIONARY_ITEM *hashtable_get_unsafe(DICTIONARY *dict, const char
259
}
260
261
static inline void hashtable_set_item_unsafe(DICTIONARY *dict, void *handle, DICTIONARY_ITEM *item) {
257
- if(dict->options & DICT_OPTION_INDEX_JUDY)
258
- hashtable_set_item_judy(dict, handle, item);
259
- else
260
- hashtable_set_item_hashtable(dict, handle, item);
262
+ hashtable_set_item_judy(dict, handle, item);
263
+// if(dict->options & DICT_OPTION_INDEX_JUDY)
264
+// hashtable_set_item_judy(dict, handle, item);
265
+// else
266
+// hashtable_set_item_hashtable(dict, handle, item);
267
}
268
269
#endif //NETDATA_DICTIONARY_HASHTABLE_H
src/libnetdata/dictionary/dictionary.c
+2
-2
@@ -497,8 +497,8 @@ static DICTIONARY *dictionary_create_internal(DICT_OPTIONS options, struct dicti
497
else
498
dict->value_aral = NULL;
499
500
- if(!(dict->options & (DICT_OPTION_INDEX_JUDY|DICT_OPTION_INDEX_HASHTABLE)))
501
- dict->options |= DICT_OPTION_INDEX_JUDY;
500
+// if(!(dict->options & (DICT_OPTION_INDEX_JUDY|DICT_OPTION_INDEX_HASHTABLE)))
501
+ dict->options |= DICT_OPTION_INDEX_JUDY;
502
503
size_t dict_size = 0;
504
dict_size += sizeof(DICTIONARY);
src/libnetdata/dictionary/dictionary.h
+1
-1
@@ -59,7 +59,7 @@ typedef enum __attribute__((packed)) dictionary_options {
59
DICT_OPTION_ADD_IN_FRONT = (1 << 4), // add dictionary items at the front of the linked list (default: at the end)
60
DICT_OPTION_FIXED_SIZE = (1 << 5), // the items of the dictionary have a fixed size
61
DICT_OPTION_INDEX_JUDY = (1 << 6), // the default, if no other indexing is set
62
- DICT_OPTION_INDEX_HASHTABLE = (1 << 7), // use SIMPLE_HASHTABLE for indexing
62
+// DICT_OPTION_INDEX_HASHTABLE = (1 << 7), // use SIMPLE_HASHTABLE for indexing
63
} DICT_OPTIONS;
64
65
struct dictionary_stats {