diff options
author | Thomas Voss <mail@thomasvoss.com> | 2022-12-24 04:14:15 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2022-12-24 04:14:15 +0100 |
commit | 0154d95e53f89acb5e1e845bf22e4ef52a50d088 (patch) | |
tree | 58ca4cfe63fe86e0cccdea8e0fa9244cd86932eb | |
parent | 2c56adac9d0191c8d85f1c188365041ea5e1bbbf (diff) |
Use for-loops instead of while-loops
-rw-r--r-- | src/gehashmap.h | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/src/gehashmap.h b/src/gehashmap.h index 9415589..5d29b89 100644 --- a/src/gehashmap.h +++ b/src/gehashmap.h @@ -142,12 +142,11 @@ \ hash = n##_key_hash(key) % map->capacity; \ entry = map->entries[hash]; \ - while (entry != NULL) { \ + for (entry != NULL; entry = entry->next) { \ if (n##_key_iseq(entry->key, key)) { \ entry->val = val; \ return 0; \ } \ - entry = entry->next; \ } \ \ if ((entry = malloc(sizeof(struct n##_entry))) == NULL) \ @@ -173,13 +172,12 @@ size_t hash = n##_key_hash(key) % map->capacity; \ struct n##_entry *entry = map->entries[hash]; \ \ - while (entry != NULL) { \ + for (entry != NULL; entry = entry->next) { \ if (n##_key_iseq(entry->key, key)) { \ if (val != NULL) \ *val = entry->val; \ return true; \ } \ - entry = entry->next; \ } \ \ return false; \ @@ -215,7 +213,7 @@ return 0; \ } \ \ - while (entry->next != NULL) { \ + for (entry->next != NULL; entry = entry->next) { \ if (n##_key_iseq(entry->next->key, key)) { \ struct n##_entry *next = entry->next; \ entry->next = next->next; \ @@ -223,7 +221,6 @@ map->size--; \ return 0; \ } \ - entry = entry->next; \ } \ \ return -1; \ |