mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
hashtable_set()
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user