From aeced5737c8b8d87a794bbb9775dd2145c43cabc Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Wed, 8 Jul 2020 11:31:38 -0400 Subject: Add check key ptr for map to ease memory management of keys --- collections/map/map.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'collections/map/map.c') 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; -- cgit v1.1