diff options
author | Tucker Evans <tucker@tuckerevans.com> | 2020-07-08 11:31:38 -0400 |
---|---|---|
committer | Tucker Evans <tucker@tuckerevans.com> | 2020-07-08 11:31:38 -0400 |
commit | aeced5737c8b8d87a794bbb9775dd2145c43cabc (patch) | |
tree | 93821c8a4550ac449c6fa0591278b3f4f2986b1e /collections/map/map.c | |
parent | 7ef7147d743b1ca1edb6d40b820c79b7527ab941 (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.c | 19 |
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; |