]> arthur.barton.de Git - netdata.git/blob - src/dictionary.h
work in progress: registry
[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         char *name;
15         void *value;
16 } NAME_VALUE;
17
18 typedef struct dictionary {
19         uint32_t flags;
20
21         unsigned long long inserts;
22         unsigned long long deletes;
23         unsigned long long searches;
24         unsigned long long entries;
25
26         avl_tree values_index;
27         pthread_rwlock_t rwlock;
28 } DICTIONARY;
29
30 #define DICTIONARY_FLAG_DEFAULT                                 0x00000000
31 #define DICTIONARY_FLAG_SINGLE_THREADED                 0x00000001
32 #define DICTIONARY_FLAG_VALUE_LINK_DONT_CLONE   0x00000002
33 #define DICTIONARY_FLAG_NAME_LINK_DONT_CLONE    0x00000004
34
35 extern DICTIONARY *dictionary_create(uint32_t flags);
36 extern void dictionary_destroy(DICTIONARY *dict);
37 extern void *dictionary_set(DICTIONARY *dict, const char *name, void *value, size_t value_len);
38 extern void *dictionary_get(DICTIONARY *dict, const char *name);
39 extern void dictionary_del(DICTIONARY *dict, const char *name);
40
41 #endif /* NETDATA_DICTIONARY_H */