aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKatharina Fey <kookie@spacekookie.de>2019-07-14 02:13:13 +0100
committerKatharina Fey <kookie@spacekookie.de>2019-07-14 18:47:18 +0100
commit98852464c7d4cd3a6a08d0208378506fdce822d6 (patch)
tree6a4a0a913ee55f7776fa0c5dd5c0544567f877af
parentc312e74f95fcfe9bd1e91c092a2d987cb067a075 (diff)
Adding a hashmap example
-rw-r--r--CMakeLists.txt11
-rw-r--r--examples/hash.c23
2 files changed, 30 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4097a78..3dd2f15 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -15,9 +15,12 @@ target_include_directories(bowl PUBLIC ".")
################### EXAMPLES ###################
if(BUILD_EXAMPLES)
- add_executable(ex_tree examples/tree.c)
- target_link_libraries(ex_tree bowl)
+ add_executable(example_tree examples/tree.c)
+ target_link_libraries(example_tree bowl)
- add_executable(ex_list examples/list.c)
- target_link_libraries(ex_list bowl)
+ add_executable(example_list examples/list.c)
+ target_link_libraries(example_list bowl)
+
+ add_executable(example_hash examples/hash.c)
+ target_link_libraries(example_hash bowl)
endif()
diff --git a/examples/hash.c b/examples/hash.c
new file mode 100644
index 0000000..7a06bbe
--- /dev/null
+++ b/examples/hash.c
@@ -0,0 +1,23 @@
+#include <bowl.h>
+
+int main()
+{
+
+ // Root node which contains a list
+ struct bowl *root;
+ bowl_malloc(&root, HASH);
+
+ struct bowl *a;
+ data_malloc(&a, LITERAL, "Destroy capitalism");
+ bowl_insert_key(root, "a", a);
+
+ struct bowl *b;
+ data_malloc(&b, INTEGER, 1312);
+ bowl_insert_key(root, "b", b);
+
+ struct bowl *c;
+ data_malloc(&c, LITERAL, "Alerta, Antifascista!");
+ bowl_insert_key(root, "c", c);
+
+ return bowl_free(root);
+}