]> arthur.barton.de Git - netdata.git/blob - src/dictionary.h
Merge branch 'master' into ab-debian
[netdata.git] / src / dictionary.h
1 #ifndef NETDATA_DICTIONARY_H
2 #define NETDATA_DICTIONARY_H 1
3
4 struct dictionary_stats {
5     unsigned long long inserts;
6     unsigned long long deletes;
7     unsigned long long searches;
8     unsigned long long entries;
9 };
10
11 typedef struct name_value {
12     avl avl;                // the index - this has to be first!
13
14     uint32_t hash;          // a simple hash to speed up searching
15                             // we first compare hashes, and only if the hashes are equal we do string comparisons
16
17     char *name;
18     void *value;
19 } NAME_VALUE;
20
21 typedef struct dictionary {
22     avl_tree values_index;
23
24     uint8_t flags;
25
26     struct dictionary_stats *stats;
27     netdata_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 #define DICTIONARY_FLAG_WITH_STATISTICS         0x00000008
35
36 extern DICTIONARY *dictionary_create(uint8_t flags);
37 extern void dictionary_destroy(DICTIONARY *dict);
38 extern void *dictionary_set(DICTIONARY *dict, const char *name, void *value, size_t value_len);
39 extern void *dictionary_get(DICTIONARY *dict, const char *name);
40 extern int dictionary_del(DICTIONARY *dict, const char *name);
41
42 extern int dictionary_get_all(DICTIONARY *dict, int (*callback)(void *entry, void *d), void *data);
43
44 #endif /* NETDATA_DICTIONARY_H */