From 448f37521dee831eda1a15f335e7dc7656c1f0dc Mon Sep 17 00:00:00 2001 From: Mineplay Date: Thu, 1 May 2025 16:20:44 -0500 Subject: [PATCH] feat(hash table): implemented is empty function --- Include/Fledasty/Core/HashTable.h | 2 ++ Src/Core/HashTable.c | 1 + Tests/Main.c | 4 ++++ 3 files changed, 7 insertions(+) diff --git a/Include/Fledasty/Core/HashTable.h b/Include/Fledasty/Core/HashTable.h index 5493434..7f052c6 100644 --- a/Include/Fledasty/Core/HashTable.h +++ b/Include/Fledasty/Core/HashTable.h @@ -50,4 +50,6 @@ FledastyError fledasty_hash_table_insert(FledastyHashTable *current_hash_table, void *fledasty_hash_table_get(FledastyHashTable *current_hash_table, void *key); FledastyError fledasty_hash_table_remove(FledastyHashTable *current_hash_table, void *key); +static inline bool fledasty_hash_table_is_empty(FledastyHashTable *current_hash_table) { return current_hash_table->size == 0; } + #endif \ No newline at end of file diff --git a/Src/Core/HashTable.c b/Src/Core/HashTable.c index 7961359..a235897 100644 --- a/Src/Core/HashTable.c +++ b/Src/Core/HashTable.c @@ -135,6 +135,7 @@ FledastyError fledasty_hash_table_remove(FledastyHashTable *current_hash_table, hallocy_free(value->value); fledasty_dynamic_array_remove_at_index(¤t_hash_table->Table[index], list_index); + current_hash_table->size -= 1; return FLEDASTY_ERROR_NONE; } diff --git a/Tests/Main.c b/Tests/Main.c index d8b7601..a5238da 100644 --- a/Tests/Main.c +++ b/Tests/Main.c @@ -206,6 +206,10 @@ int main() { printf("Hash table get: %d\n", *hash_table_value); } + if (fledasty_hash_table_is_empty(&test_hash_table)) { + printf("Hash table is empty\n"); + } + fledasty_hash_table_destroy(&test_hash_table); printf("Done\n"); return 0;