hashtable_set()

This commit is contained in:
Matheus
2022-07-31 14:18:13 -03:00
parent 151235694d
commit 3653e01505
2 changed files with 17 additions and 2 deletions
+1
View File
@@ -20,5 +20,6 @@ bool hashtable_insert(hashtable*, char*, void*);
bool hashtable_remove(hashtable*, char*);
void hashtable_destroy(hashtable*);
void* hashtable_get(hashtable*, char*);
bool* hashtable_set(hashtable*, char*, void*);
#endif
+16 -2
View File
@@ -2,8 +2,6 @@
#include <string.h>
#include <kernel/alloc.h>
// temporary for testing
size_t hash(char* ptr, size_t size){
size_t hash = 0;
for(size_t i = 0; i < size; ++i){
@@ -98,6 +96,22 @@ bool hashtable_remove(hashtable* table, char* key){
}
bool hashtable_set(hashtable* table, char* key, void* value){
hashtableentry* entry = getentry(table, key);
if(!entry->key)
return false;
while(entry && strcmp(entry->key, key))
entry = entry->next;
if(!entry) return false;
entry->val = value;
return true;
}
void* hashtable_get(hashtable* table, char* key){
hashtableentry* entry = getentry(table, key);