@@ 20,17 20,13 @@ void *ko_hashtable_get(struct ko_hashtable *table, const char *key) {
unsigned int hash = djb2(key);
unsigned int bucket = hash % buckets_size;
struct ko_hashtable_entry *entry = table->buckets[bucket];
- if (entry) {
- if (entry->hash != hash || strcmp(entry->key, key) != 0) {
- while (entry->next) {
- entry = entry->next;
- if (!entry || (entry->hash == hash &&
- strcmp(entry->key, key) == 0)) {
- break;
- }
- }
+ do {
+ if (!entry || (entry->hash == hash &&
+ strcmp(entry->key, key) == 0)) {
+ break;
}
- }
+ entry = entry->next;
+ } while (entry);
return entry ? entry->value : NULL;
}
@@ 40,18 36,13 @@ void *ko_hashtable_set(struct ko_hashtable *table, const char *key, void *value)
struct ko_hashtable_entry *entry = table->buckets[bucket];
struct ko_hashtable_entry *previous = NULL;
- if (entry) {
- if (entry->hash != hash || strcmp(entry->key, key) != 0) {
- while (entry->next) {
- previous = entry;
- entry = entry->next;
- if (!entry || (entry->hash == hash &&
- strcmp(entry->key, key) == 0)) {
- break;
- }
- }
+ do {
+ if (!entry || (entry->hash == hash && strcmp(entry->key, key) == 0)) {
+ break;
}
- }
+ previous = entry;
+ entry = entry->next;
+ } while (entry);
if (entry == NULL) {
entry = calloc(1, sizeof(struct ko_hashtable_entry));