aboutsummaryrefslogtreecommitdiff
path: root/collections/map/map.c
diff options
context:
space:
mode:
authorTucker Evans <tucker@tuckerevans.com>2020-07-08 11:31:38 -0400
committerTucker Evans <tucker@tuckerevans.com>2020-07-08 11:31:38 -0400
commitaeced5737c8b8d87a794bbb9775dd2145c43cabc (patch)
tree93821c8a4550ac449c6fa0591278b3f4f2986b1e /collections/map/map.c
parent7ef7147d743b1ca1edb6d40b820c79b7527ab941 (diff)
Add check key ptr for map to ease memory management of keys
Diffstat (limited to 'collections/map/map.c')
-rw-r--r--collections/map/map.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/collections/map/map.c b/collections/map/map.c
index 00f2225..66382ba 100644
--- a/collections/map/map.c
+++ b/collections/map/map.c
@@ -102,6 +102,25 @@ void *key, *val;
return -1;
}
+int map_check_key_ptr(root, key)
+map *root;
+void *key;
+{
+ int cmp;
+
+ if (!root || !key)
+ return 0;
+
+ cmp = root->cmp(root->key, key);
+
+ if (cmp < 0)
+ return map_check_key_ptr(root->left, key);
+ if (cmp > 0)
+ return map_check_key_ptr(root->right, key);
+
+ return root->key == key;
+}
+
void* map_set_key(root, key)
map *root;
void *key;