summaryrefslogtreecommitdiffstats
path: root/src/libnetdata/c_rhash/c_rhash.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-11-25 14:45:37 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-11-25 14:48:03 +0000
commite55403ed71282d7bfd8b56df219de3c28a8af064 (patch)
tree524889e5becb81643bf8741e3082955dca076f09 /src/libnetdata/c_rhash/c_rhash.h
parentReleasing debian version 1.47.5-1. (diff)
downloadnetdata-e55403ed71282d7bfd8b56df219de3c28a8af064.tar.xz
netdata-e55403ed71282d7bfd8b56df219de3c28a8af064.zip
Merging upstream version 2.0.3+dfsg:
- does not include dygraphs anymore (Closes: #923993) - does not include pako anymore (Closes: #1042533) - does not include dashboard binaries anymore (Closes: #1045145) Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/libnetdata/c_rhash/c_rhash.h')
-rw-r--r--src/libnetdata/c_rhash/c_rhash.h63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/libnetdata/c_rhash/c_rhash.h b/src/libnetdata/c_rhash/c_rhash.h
new file mode 100644
index 000000000..990ef5432
--- /dev/null
+++ b/src/libnetdata/c_rhash/c_rhash.h
@@ -0,0 +1,63 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#ifndef C_RHASH_H
+#define C_RHASH_H
+#include "../libnetdata.h"
+
+#ifndef DEFAULT_BIN_COUNT
+ #define DEFAULT_BIN_COUNT 1000
+#endif
+
+#define ITEMTYPE_UNSET (0x0)
+#define ITEMTYPE_STRING (0x1)
+#define ITEMTYPE_UINT8 (0x2)
+#define ITEMTYPE_UINT64 (0x3)
+#define ITEMTYPE_OPAQUE_PTR (0x4)
+
+typedef struct c_rhash_s *c_rhash;
+
+c_rhash c_rhash_new(size_t bin_count);
+
+void c_rhash_destroy(c_rhash hash);
+
+// # Insert
+// ## Insert where key is string
+int c_rhash_insert_str_ptr(c_rhash hash, const char *key, void *value);
+int c_rhash_insert_str_uint8(c_rhash hash, const char *key, uint8_t value);
+// ## Insert where key is uint64
+int c_rhash_insert_uint64_ptr(c_rhash hash, uint64_t key, void *value);
+
+// # Get
+// ## Get where key is string
+int c_rhash_get_ptr_by_str(c_rhash hash, const char *key, void **ret_val);
+int c_rhash_get_uint8_by_str(c_rhash hash, const char *key, uint8_t *ret_val);
+// ## Get where key is uint64
+int c_rhash_get_ptr_by_uint64(c_rhash hash, uint64_t key, void **ret_val);
+
+typedef struct {
+ size_t bin;
+ struct bin_item *item;
+ int initialized;
+} c_rhash_iter_t;
+
+#define C_RHASH_ITER_T_INITIALIZER { .bin = 0, .item = NULL, .initialized = 0 }
+
+#define c_rhash_iter_t_initialize(p_iter) memset(p_iter, 0, sizeof(c_rhash_iter_t))
+
+/*
+ * goes trough whole hash map and returns every
+ * type uint64 key present/stored
+ *
+ * it is not necessary to finish iterating and iterator can be reinitialized
+ * there are no guarantees on the order in which the keys will come
+ * behavior here is implementation dependent and can change any time
+ *
+ * returns:
+ * 0 for every key and stores the key in *key
+ * 1 on error or when all keys of this type has been already iterated over
+ */
+int c_rhash_iter_uint64_keys(c_rhash hash, c_rhash_iter_t *iter, uint64_t *key);
+
+int c_rhash_iter_str_keys(c_rhash hash, c_rhash_iter_t *iter, const char **key);
+
+#endif