aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTucker Evans <tucker@tuckerevans.com>2020-07-06 15:36:34 -0400
committerTucker Evans <tucker@tuckerevans.com>2020-07-08 10:56:29 -0400
commitf652c23fbc61dec9db48c6e745edca5a12b655bb (patch)
tree55041979d41e9a1f2b501d2db2fa22cb58b0c7fc
parent7f96fdd283c7e6ce7245585d75795a69871e0635 (diff)
Add structs/typedefs for maps
-rw-r--r--collections/map/map.adoc32
-rw-r--r--collections/map/map.c11
-rw-r--r--collections/map/map.h7
3 files changed, 50 insertions, 0 deletions
diff --git a/collections/map/map.adoc b/collections/map/map.adoc
new file mode 100644
index 0000000..a43ae1d
--- /dev/null
+++ b/collections/map/map.adoc
@@ -0,0 +1,32 @@
+Map
+===
+Tucker Evans
+v0.0, 2020-07-06
+
+A basic map implemented in an AVL tree.
+
+NOTE: Keys are passed as void pointers and their data is not copied (this
+should be handled by the user), they should not be freed without clearing the
+map.
+
+NOTE: There is currently no way to distinquish between a failed retrieval
+(pop, index, back, etc.) and returning a NULL value. Keep this in mind if
+you plan on storing NULL values in the vector, there are plans to fix this in
+the future.
+
+Types
+----
+The following types are defined in the header file:
+[[map]]
++map+
+~~~~~
+This structure holds all internal information regarding a map.
+All functions (except constructors) expect a pointer to this struct as their
+first parameter.
+
+[[cmp_func]]
++cmp_func+
+~~~~~~~~~~~
+This is a pointer to a function that to compare keys from pointers. This
+typedef is provided to cast comparison functions as a map expects the
+comparison function to take void* as its parameters.
diff --git a/collections/map/map.c b/collections/map/map.c
new file mode 100644
index 0000000..21af21c
--- /dev/null
+++ b/collections/map/map.c
@@ -0,0 +1,11 @@
+#include "map.h"
+
+#include <string.h>
+#include <stdio.h>
+
+struct map_node {
+ void *key, *val;
+ cmp_func cmp;
+
+ struct map_node *left, *right, *parent;
+};
diff --git a/collections/map/map.h b/collections/map/map.h
new file mode 100644
index 0000000..a760b45
--- /dev/null
+++ b/collections/map/map.h
@@ -0,0 +1,7 @@
+#ifndef MAP_H
+#define MAP_H
+
+typedef struct map_node map;
+typedef int (*cmp_func)(void*, void*);
+
+#endif