created HashMap iterator

This commit is contained in:
2025-11-10 10:30:22 +05:00
parent 2de044711f
commit 6a1067a612
2 changed files with 81 additions and 19 deletions

View File

@@ -6,13 +6,13 @@
typedef void (*FreeFunction)(void*);
typedef struct KeyHash {
typedef struct HashMapKeyHash {
str key;
u32 hash;
} KeyHash;
} HashMapKeyHash;
typedef struct HashMapBucket {
List(KeyHash) key_hash_list;
List(HashMapKeyHash) key_hash_list;
List(T) value_list;
} HashMapBucket;
@@ -34,3 +34,23 @@ bool HashMap_tryPush(HashMap_* self, const str key, void* value_ptr);
void HashMap_pushOrUpdate(HashMap_* self, const str key, void* value_ptr);
NULLABLE(void*) HashMap_tryGetPtr(const HashMap_* self, const str key);
bool HashMap_tryDelete(HashMap_* self, const str key);
typedef struct {
const HashMap_* map;
i32 bucket_n;
i32 elem_n;
} HashMapIter;
typedef struct HashMapKeyValue {
str key;
void* value;
} HashMapKeyValue;
static inline HashMapIter HashMapIter_create(const HashMap_* table){
return (HashMapIter){ .map = table, .bucket_n = -1, .elem_n = -1 };
}
bool HashMapIter_moveNext(HashMapIter* self);
/// don't forget to call HashMapIter_moveNext() first
bool HashMapIter_getCurrent(HashMapIter* self, HashMapKeyValue* kv);