From b0f70edf052f7f8de78025144e8cd9d115ecdb16 Mon Sep 17 00:00:00 2001 From: Vratislav Podzimek Date: Fri, 3 Nov 2023 12:16:05 +0100 Subject: [PATCH] Change MapSize() complexity to O(1) even if it's a hash map No need to iterate, a HashMap has the `load` field which contains the number of elements in the map. Ticket: CFE-3043 Changelog: Complexity of MapSize() is now O(1) in all cases --- libutils/map.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/libutils/map.c b/libutils/map.c index 94ae40a5..bb50cc37 100644 --- a/libutils/map.c +++ b/libutils/map.c @@ -118,15 +118,7 @@ size_t MapSize(const Map *map) } else { - MapIterator i = MapIteratorInit((Map*)map); - size_t size = 0; - - while (MapIteratorNext(&i)) - { - size++; - } - - return size; + return map->hashmap->load; } }