X-Git-Url: https://arthur.barton.de/gitweb/?a=blobdiff_plain;f=src%2Fdictionary.h;h=f028dbb30e39f81b182e993237d243bac0f4557c;hb=e3fe7e2ef42eaa7e039db54612c6c736da7d96fa;hp=fe44d8146093f3c3e2fe0dc472b04880b14bbce1;hpb=2876d83b354330b2b05e02a378552eb02d675d98;p=netdata.git diff --git a/src/dictionary.h b/src/dictionary.h index fe44d814..f028dbb3 100644 --- a/src/dictionary.h +++ b/src/dictionary.h @@ -1,61 +1,44 @@ -#include - -#include "web_buffer.h" -#include "avl.h" - #ifndef NETDATA_DICTIONARY_H #define NETDATA_DICTIONARY_H 1 +struct dictionary_stats { + unsigned long long inserts; + unsigned long long deletes; + unsigned long long searches; + unsigned long long entries; +}; + typedef struct name_value { - avl avl; // the index - this has to be first! + avl avl; // the index - this has to be first! - uint32_t hash; // a simple hash to speed up searching - // we first compare hashes, and only if the hashes are equal we do string comparisons + uint32_t hash; // a simple hash to speed up searching + // we first compare hashes, and only if the hashes are equal we do string comparisons - char *name; - void *value; + char *name; + void *value; } NAME_VALUE; typedef struct dictionary { - avl_tree values_index; + avl_tree values_index; - uint8_t flags; + uint8_t flags; -#ifdef NETDATA_DICTIONARY_WITH_STATISTICS - unsigned long long inserts; - unsigned long long deletes; - unsigned long long searches; - unsigned long long entries; -#endif /* NETDATA_DICTIONARY_WITH_STATISTICS */ - - pthread_rwlock_t rwlock; + struct dictionary_stats *stats; + netdata_rwlock_t *rwlock; } DICTIONARY; -#ifdef NETDATA_DICTIONARY_WITH_STATISTICS -#define NETDATA_DICTIONARY_STATS_INSERTS_PLUS1(dict) (dict)->inserts++ -#define NETDATA_DICTIONARY_STATS_DELETES_PLUS1(dict) (dict)->deletes++ -#define NETDATA_DICTIONARY_STATS_SEARCHES_PLUS1(dict) (dict)->searches++ -#define NETDATA_DICTIONARY_STATS_ENTRIES_PLUS1(dict) (dict)->entries++ -#define NETDATA_DICTIONARY_STATS_ENTRIES_MINUS1(dict) (dict)->entries-- -#else /* NETDATA_DICTIONARY_WITH_STATISTICS */ -#define NETDATA_DICTIONARY_STATS_INSERTS_PLUS1(dict) -#define NETDATA_DICTIONARY_STATS_DELETES_PLUS1(dict) -#define NETDATA_DICTIONARY_STATS_SEARCHES_PLUS1(dict) -#define NETDATA_DICTIONARY_STATS_ENTRIES_PLUS1(dict) -#define NETDATA_DICTIONARY_STATS_ENTRIES_MINUS1(dict) -#endif /* NETDATA_DICTIONARY_WITH_STATISTICS */ - -#define DICTIONARY_FLAG_DEFAULT 0x00000000 -#define DICTIONARY_FLAG_SINGLE_THREADED 0x00000001 -#define DICTIONARY_FLAG_VALUE_LINK_DONT_CLONE 0x00000002 -#define DICTIONARY_FLAG_NAME_LINK_DONT_CLONE 0x00000004 - -extern DICTIONARY *dictionary_create(uint32_t flags); +#define DICTIONARY_FLAG_DEFAULT 0x00000000 +#define DICTIONARY_FLAG_SINGLE_THREADED 0x00000001 +#define DICTIONARY_FLAG_VALUE_LINK_DONT_CLONE 0x00000002 +#define DICTIONARY_FLAG_NAME_LINK_DONT_CLONE 0x00000004 +#define DICTIONARY_FLAG_WITH_STATISTICS 0x00000008 + +extern DICTIONARY *dictionary_create(uint8_t flags); extern void dictionary_destroy(DICTIONARY *dict); extern void *dictionary_set(DICTIONARY *dict, const char *name, void *value, size_t value_len); extern void *dictionary_get(DICTIONARY *dict, const char *name); extern int dictionary_del(DICTIONARY *dict, const char *name); -extern int dictionary_get_all(DICTIONARY *dict, int (*callback)(void *entry, void *data), void *data); +extern int dictionary_get_all(DICTIONARY *dict, int (*callback)(void *entry, void *d), void *data); #endif /* NETDATA_DICTIONARY_H */