]> arthur.barton.de Git - netdata.git/blob - src/dictionary.h
e1320da3d5a172c4c561f1b4ecbd08691577e3fc
[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 typedef struct name_value {
10         avl avl;                                // the index - this has to be first!
11
12         uint32_t hash;                  // a simple hash to speed up searching
13                                                         // we first compare hashes, and only if the hashes are equal we do string comparisons
14
15         char *name;
16         void *value;
17 } NAME_VALUE;
18
19 typedef struct dictionary {
20         uint32_t flags;
21
22         unsigned long long inserts;
23         unsigned long long deletes;
24         unsigned long long searches;
25         unsigned long long entries;
26
27         avl_tree values_index;
28         pthread_rwlock_t rwlock;
29         pthread_mutex_t atomic_mutex;
30 } DICTIONARY;
31
32 #define DICTIONARY_FLAG_DEFAULT                                 0x00000000
33 #define DICTIONARY_FLAG_SINGLE_THREADED                 0x00000001
34 #define DICTIONARY_FLAG_VALUE_LINK_DONT_CLONE   0x00000002
35 #define DICTIONARY_FLAG_NAME_LINK_DONT_CLONE    0x00000004
36
37 extern DICTIONARY *dictionary_create(uint32_t flags);
38 extern void dictionary_destroy(DICTIONARY *dict);
39 extern void *dictionary_set(DICTIONARY *dict, const char *name, void *value, size_t value_len);
40 extern void *dictionary_get(DICTIONARY *dict, const char *name);
41 extern int dictionary_del(DICTIONARY *dict, const char *name);
42
43 extern int dictionary_get_all(DICTIONARY *dict, int (*callback)(void *entry, void *data), void *data);
44
45 #endif /* NETDATA_DICTIONARY_H */