aboutsummaryrefslogtreecommitdiff
path: root/collections/map/map.c
diff options
context:
space:
mode:
authorTucker Evans <tucker@tuckerevans.com>2020-07-06 17:26:10 -0400
committerTucker Evans <tucker@tuckerevans.com>2020-07-08 10:56:36 -0400
commit20c79049e9b0a6a1aa47b1b9dacfbb31b6e7c992 (patch)
tree761f68ac650e7f974c0a45c61e980ce0fbe9881c /collections/map/map.c
parent50846316de122801e07511d4e3771a4561efa5ad (diff)
Add clear & free functions for maps
Diffstat (limited to 'collections/map/map.c')
-rw-r--r--collections/map/map.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/collections/map/map.c b/collections/map/map.c
index 712a895..beb8f7f 100644
--- a/collections/map/map.c
+++ b/collections/map/map.c
@@ -34,3 +34,47 @@ map *root;
return map_size(root->left) + map_size(root->right) + 1;
}
+
+void map_clear(root)
+map *root;
+{
+ map *l, *r;
+
+ l = root->left;
+ r = root->right;
+
+ if (!root)
+ return;
+
+ if (root->parent) {
+ free(root->key);
+ root->key = NULL;
+
+ free(root->val);
+ root->val = NULL;
+
+ root->parent = NULL;
+
+ free(root);
+ }
+
+ map_clear(l);
+ map_clear(r);
+}
+
+void map_free(root)
+map *root;
+{
+ if (!root)
+ return;
+
+ root->key = NULL;
+
+ map_free(root->left);
+ root->left = NULL;
+
+ map_free(root->right);
+ root->right = NULL;
+
+ free(root);
+}