]> arthur.barton.de Git - netdata.git/blob - src/dictionary.h
lower dictionary memory requirements by keeping pointers to optional features
[netdata.git] / src / dictionary.h
1 #include <pthread.h>
2
3 #include "web_buffer.h"
4 #include "avl.h"
5
6 #ifndef NETDATA_DICTIONARY_H
7 #define NETDATA_DICTIONARY_H 1
8
9 struct dictionary_stats {
10         unsigned long long inserts;
11         unsigned long long deletes;
12         unsigned long long searches;
13         unsigned long long entries;
14 };
15
16 typedef struct name_value {
17         avl avl;                                // the index - this has to be first!
18
19         uint32_t hash;                  // a simple hash to speed up searching
20                                                         // we first compare hashes, and only if the hashes are equal we do string comparisons
21
22         char *name;
23         void *value;
24 } NAME_VALUE;
25
26 typedef struct dictionary {
27         avl_tree values_index;
28
29         uint8_t flags;
30
31         struct dictionary_stats *stats;
32         pthread_rwlock_t *rwlock;
33 } DICTIONARY;
34
35 #define DICTIONARY_FLAG_DEFAULT                                 0x00000000
36 #define DICTIONARY_FLAG_SINGLE_THREADED                 0x00000001
37 #define DICTIONARY_FLAG_VALUE_LINK_DONT_CLONE   0x00000002
38 #define DICTIONARY_FLAG_NAME_LINK_DONT_CLONE    0x00000004
39 #define DICTIONARY_FLAG_WITH_STATISTICS                 0x00000008
40
41 extern DICTIONARY *dictionary_create(uint32_t flags);
42 extern void dictionary_destroy(DICTIONARY *dict);
43 extern void *dictionary_set(DICTIONARY *dict, const char *name, void *value, size_t value_len);
44 extern void *dictionary_get(DICTIONARY *dict, const char *name);
45 extern int dictionary_del(DICTIONARY *dict, const char *name);
46
47 extern int dictionary_get_all(DICTIONARY *dict, int (*callback)(void *entry, void *data), void *data);
48
49 #endif /* NETDATA_DICTIONARY_H */