aboutsummaryrefslogtreecommitdiff
path: root/include/std
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-01-20 23:00:39 +0100
committerdec05eba <dec05eba@protonmail.com>2020-01-20 23:00:39 +0100
commit108018e3e7326dabbbef568ab08bc5cebf5d427b (patch)
tree7c9a522276aea7015638492592eba02615b78d43 /include/std
parent50c928d224bff0af322f23a7d2b842cd54aa2e68 (diff)
Add arithmetic, implement hash map
Diffstat (limited to 'include/std')
-rw-r--r--include/std/buffer.h4
-rw-r--r--include/std/hash_map.h24
-rw-r--r--include/std/string_view.h11
3 files changed, 38 insertions, 1 deletions
diff --git a/include/std/buffer.h b/include/std/buffer.h
index dea7dbd..db6474e 100644
--- a/include/std/buffer.h
+++ b/include/std/buffer.h
@@ -16,6 +16,8 @@ typedef struct {
void tsl_buffer_init(TslBuffer *self);
void tsl_buffer_deinit(TslBuffer *self);
-int tsl_buffer_append(TslBuffer *self, void *data, size_t size);
+int tsl_buffer_append(TslBuffer *self, const void *data, size_t size);
+void* tsl_buffer_begin(TslBuffer *self);
+void* tsl_buffer_end(TslBuffer *self);
#endif /* TSL_BUFFER_H */
diff --git a/include/std/hash_map.h b/include/std/hash_map.h
new file mode 100644
index 0000000..f3a3a6d
--- /dev/null
+++ b/include/std/hash_map.h
@@ -0,0 +1,24 @@
+#ifndef TSL_HASH_MAP_H
+#define TSL_HASH_MAP_H
+
+#include "string_view.h"
+#include <stdint.h>
+
+typedef uint64_t (*TslHashFunc)(const void *data, size_t size);
+
+/* TODO: Optimize small hash map by using the members of the struct instead of allocating on heap */
+typedef struct {
+ void *buckets_data; /* value=TslHashMapNode<void*>, data=|hash(uint64_t) + key_size(size_t) + key_data(...) data_size(size_t) + data_data(...)| */
+ size_t buckets_size;
+ size_t buckets_capacity;
+ size_t num_items;
+} TslHashMap;
+
+void tsl_hash_map_init(TslHashMap *self);
+void tsl_hash_map_deinit(TslHashMap *self);
+
+int tsl_hash_map_insert(TslHashMap *self, const TslStringView *key, const void *data, size_t size, TslHashFunc hash_func);
+/* Get a reference to the value by key @key */
+void* tsl_hash_map_get(TslHashMap *self, const TslStringView *key, TslHashFunc hash_func);
+
+#endif /* TSL_HASH_MAP_H */
diff --git a/include/std/string_view.h b/include/std/string_view.h
new file mode 100644
index 0000000..4f9552a
--- /dev/null
+++ b/include/std/string_view.h
@@ -0,0 +1,11 @@
+#ifndef TSL_STRING_VIEW_H
+#define TSL_STRING_VIEW_H
+
+#include <stddef.h>
+
+typedef struct {
+ const char *data;
+ size_t size;
+} TslStringView;
+
+#endif /* TSL_STRING_VIEW_H */