dictionary.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #ifndef NETDATA_DICTIONARY_H
  3. #define NETDATA_DICTIONARY_H 1
  4. #include "../libnetdata.h"
  5. struct dictionary_stats {
  6. unsigned long long inserts;
  7. unsigned long long deletes;
  8. unsigned long long searches;
  9. unsigned long long entries;
  10. };
  11. typedef struct name_value {
  12. avl_t avl_node; // the index - this has to be first!
  13. uint32_t hash; // a simple hash to speed up searching
  14. // we first compare hashes, and only if the hashes are equal we do string comparisons
  15. char *name;
  16. void *value;
  17. } NAME_VALUE;
  18. typedef struct dictionary {
  19. avl_tree_type values_index;
  20. uint8_t flags;
  21. struct dictionary_stats *stats;
  22. netdata_rwlock_t *rwlock;
  23. } DICTIONARY;
  24. #define DICTIONARY_FLAG_DEFAULT 0x00000000
  25. #define DICTIONARY_FLAG_SINGLE_THREADED 0x00000001
  26. #define DICTIONARY_FLAG_VALUE_LINK_DONT_CLONE 0x00000002
  27. #define DICTIONARY_FLAG_NAME_LINK_DONT_CLONE 0x00000004
  28. #define DICTIONARY_FLAG_WITH_STATISTICS 0x00000008
  29. extern DICTIONARY *dictionary_create(uint8_t flags);
  30. extern void dictionary_destroy(DICTIONARY *dict);
  31. extern void *dictionary_set(DICTIONARY *dict, const char *name, void *value, size_t value_len) NEVERNULL;
  32. extern void *dictionary_get(DICTIONARY *dict, const char *name);
  33. extern int dictionary_del(DICTIONARY *dict, const char *name);
  34. extern int dictionary_get_all(DICTIONARY *dict, int (*callback)(void *entry, void *d), void *data);
  35. extern int dictionary_get_all_name_value(DICTIONARY *dict, int (*callback)(char *name, void *entry, void *d), void *data);
  36. #endif /* NETDATA_DICTIONARY_H */