From e243ad949a822044a6d5710b7390e1a48b784dff Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 26 Feb 2023 22:41:58 +1100 Subject: [PATCH] Removed a divide instruction (modulo) from the final output, thanks Wren! --- source/toy_literal_dictionary.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/source/toy_literal_dictionary.c b/source/toy_literal_dictionary.c index 355aeca..4c6e94a 100644 --- a/source/toy_literal_dictionary.c +++ b/source/toy_literal_dictionary.c @@ -22,11 +22,13 @@ static Toy_private_dictionary_entry* getEntryArray(Toy_private_dictionary_entry* } //find "key", starting at index - unsigned int index = hash % capacity; - unsigned int start = index; + int index = hash % capacity; + int start = index; //increment once, so it can't equal start - index = (index + 1) % capacity; + if (++index >= capacity) { + index = 0; + } //literal probing and collision checking while (index != start) { //WARNING: this is the only function allowed to retrieve an entry from the array @@ -44,7 +46,10 @@ static Toy_private_dictionary_entry* getEntryArray(Toy_private_dictionary_entry* } } - index = (index + 1) % capacity; + if (++index >= capacity) { + index = 0; + } + //index = (index + 1) % capacity; } return NULL;