mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
hashtables: isset()
This commit is contained in:
@@ -24,5 +24,6 @@ bool hashtable_remove(hashtable*, char*);
|
||||
void hashtable_destroy(hashtable*);
|
||||
void* hashtable_get(hashtable*, char*);
|
||||
bool hashtable_set(hashtable*, char*, void*);
|
||||
bool hashtable_isset(hashtable*, char*);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -27,6 +27,24 @@ static inline hashtableentry* getentry(hashtable* table, char* key){
|
||||
return &table->entries[entryn];
|
||||
}
|
||||
|
||||
bool hashtable_isset(hashtable* table, char* key){
|
||||
|
||||
hashtableentry* entry = getentry(table, key);
|
||||
|
||||
if(!entry)
|
||||
return false;
|
||||
|
||||
if(!entry->key)
|
||||
return false;
|
||||
|
||||
while(entry && strcmp(entry->key, key))
|
||||
entry = entry->next;
|
||||
|
||||
if(!entry) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void* hashtable_fromoffset(hashtable* table, uintmax_t offset, char* retkey){
|
||||
|
||||
for(uintmax_t i = 0; i < table->size; ++i){
|
||||
@@ -164,8 +182,8 @@ void* hashtable_get(hashtable* table, char* key){
|
||||
|
||||
void hashtable_destroy(hashtable* table){
|
||||
|
||||
// would be cool if this also deleted non removed entries
|
||||
|
||||
// TODO fix memory leak bruh
|
||||
|
||||
free(table->entries);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user