aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorMikhail Romanko <me@blankhex.com>2024-04-13 14:52:29 +0300
committerMikhail Romanko <me@blankhex.com>2024-04-13 14:52:29 +0300
commitac5df0ebe9a6ac67b9be4cc319f5cd0625b50178 (patch)
tree5532f9fd219691476fb3be127f228f3a07325e4b /main.c
downloadbhlib-old-ac5df0ebe9a6ac67b9be4cc319f5cd0625b50178.tar.gz
Initial commit
Diffstat (limited to 'main.c')
-rw-r--r--main.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..8cd7e5a
--- /dev/null
+++ b/main.c
@@ -0,0 +1,83 @@
+#include <bh/queue.h>
+#include <bh/hashmap.h>
+#include <stdio.h>
+#include <stdint.h>
+
+#define BH_INT_TO_PTR(x) \
+ ((void *)((long)(x)))
+
+#define BH_UINT_TO_PTR(x) \
+ ((void *)((unsigned long)(x)))
+
+#define BH_PTR_TO_INT(x) \
+ ((long)(x))
+
+#define BH_PTR_TO_UINT(x) \
+ ((unsigned long)(x))
+
+size_t ptr_hash(const void *item)
+{
+ return BH_PTR_TO_INT(item);
+}
+
+int ptr_equal(const void *lhs, const void *rhs)
+{
+ return BH_PTR_TO_INT(lhs) - BH_PTR_TO_INT(rhs);
+}
+
+void foo()
+{
+ bh_hashmap_t *hashmap;
+ size_t i;
+ void *iter;
+
+ hashmap = bh_hashmap_new((bh_equal_cb_t)ptr_equal, (bh_hash_cb_t)ptr_hash);
+
+ for (i = 0; i < 16; i++)
+ bh_hashmap_insert(hashmap, (void*)i, (void*)(i * 4));
+
+ iter = bh_hashmap_iter_next(hashmap, NULL);
+ while (iter)
+ {
+ printf("%zu: %zu\n", BH_PTR_TO_INT(bh_hashmap_iter_key(iter)), BH_PTR_TO_INT(bh_hashmap_iter_value(iter)));
+ iter = bh_hashmap_iter_next(hashmap, iter);
+ }
+
+ bh_hashmap_free(hashmap);
+}
+
+int main()
+{
+ bh_queue_t *queue;
+ void *iter;
+ size_t i, j;
+
+ foo();
+
+ queue = bh_queue_new();
+
+ for (j = 0; j < 32; j++)
+ {
+ printf("%zu %zu\n", bh_queue_size(queue), bh_queue_capacity(queue));
+
+ for (i = 0; i < 4; i++)
+ bh_queue_insert(queue, (void *)(j * 4 + i));
+
+ printf("%zu %zu\n", bh_queue_size(queue), bh_queue_capacity(queue));
+
+ for (i = 0; i < 2; i++)
+ bh_queue_remove(queue);
+ }
+
+ printf("%zu %zu\n", bh_queue_size(queue), bh_queue_capacity(queue));
+
+ iter = bh_queue_iter_next(queue, NULL);
+ while (iter)
+ {
+ printf("%d\n", (int)bh_queue_iter_value(iter));
+ iter = bh_queue_iter_next(queue, iter);
+ }
+
+ bh_queue_free(queue);
+ return 0;
+}