From 78fa3e40d3c2f0d302f4779ca35352f5f68fba0b Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Wed, 8 Jul 2020 11:15:18 -0400 Subject: Fix map insert error returns Makes inserting an equivalent key an error, set_val should be used. --- collections/map/map.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'collections/map/map.c') diff --git a/collections/map/map.c b/collections/map/map.c index b21ed32..62cb016 100644 --- a/collections/map/map.c +++ b/collections/map/map.c @@ -82,24 +82,24 @@ void *key, *val; cmp = root->cmp(root->key, key); - if (cmp == 0 && root->key == key) { - root->val = val; - } else if (cmp < 0) { + if (cmp < 0) { if (!root->left) root->left = map_new_from_parent(root); map_insert(root->left, key, val); - } else if (cmp > 0) { + return 0; + } + + if (cmp > 0) { if (!root->right) root->right = map_new_from_parent(root); map_insert(root->right, key, val); - } else { - return -1; + return 0; } - return 0; + return -1; } void* map_reset_key(root, key) -- cgit v1.1