Add hash map implementation
Release / release (push) Successful in 3s

This commit is contained in:
2026-09-24 00:52:34 +01:00
parent 68640dc5e2
commit 180292289d
14 changed files with 811 additions and 8 deletions
+10 -2
View File
@@ -1,6 +1,7 @@
// vim:fileencoding=utf-8:foldmethod=marker
#include "wapp.h"
#include "test_hashset.h"
wp_persist inline WpU8Stream encoder(void *data);
wp_persist inline b8 key_eq(void *a, void *b);
@@ -27,6 +28,13 @@ WpTestFuncResult test_hashset_alloc(void) {
return wpTesterResult(result);
}
WpTestFuncResult test_hashset_get_item_size(void) {
b8 result = true;
WpHashSet set = wpHashSet(WpStr8, encoder, key_eq, 8);
result = result && wpHashSetItemSize(&set) == sizeof(WpStr8);
return wpTesterResult(result);
}
WpTestFuncResult test_hashset_find(void) {
b8 result = true;
WpHashSet set = wpHashSet(WpStr8, encoder, key_eq, 8);
@@ -70,7 +78,7 @@ WpTestFuncResult test_hashset_insert_capped(void) {
result = result && wpHashSetCapacity(&set) == 4 && wpHashSetCount(&set) == 3;
for (u64 i = 0; i < 3; ++i) {
result = result && wpStr8Equal(wpArrayGet(WpStr8, set.keys, i), &keys[i]);
result = result && wpStr8Equal(&wpHashSetItems(WpStr8, &set)[i], &keys[i]);
}
return wpTesterResult(result);
@@ -95,7 +103,7 @@ WpTestFuncResult test_hashset_insert_alloc(void) {
}
result = result && set.keys != set_keys && wpHashSetCapacity(&set) == 8 && wpHashSetCount(&set) == 4;
for (u64 i = 0; i < 3; ++i) {
for (u64 i = 0; i < wpArrayCount(keys); ++i) {
result = result && wpStr8Equal(&wpHashSetItems(WpStr8, &set)[i], &keys[i]);
}
+10 -2
View File
@@ -1,6 +1,7 @@
// vim:fileencoding=utf-8:foldmethod=marker
#include "wapp.h"
#include "test_hashset.h"
wp_persist inline WpU8Stream encoder(void *data);
wp_persist inline b8 key_eq(void *a, void *b);
@@ -27,6 +28,13 @@ WpTestFuncResult test_hashset_alloc(void) {
return wpTesterResult(result);
}
WpTestFuncResult test_hashset_get_item_size(void) {
b8 result = true;
WpHashSet set = wpHashSet(WpStr8, encoder, key_eq, 8);
result = result && wpHashSetItemSize(&set) == sizeof(WpStr8);
return wpTesterResult(result);
}
WpTestFuncResult test_hashset_find(void) {
b8 result = true;
WpHashSet set = wpHashSet(WpStr8, encoder, key_eq, 8);
@@ -66,7 +74,7 @@ WpTestFuncResult test_hashset_insert_capped(void) {
result = result && wpHashSetCapacity(&set) == 4 && wpHashSetCount(&set) == 3;
for (u64 i = 0; i < 3; ++i) {
result = result && wpStr8Equal(wpArrayGet(WpStr8, set.keys, i), &keys[i]);
result = result && wpStr8Equal(&wpHashSetItems(WpStr8, &set)[i], &keys[i]);
}
return wpTesterResult(result);
@@ -89,7 +97,7 @@ WpTestFuncResult test_hashset_insert_alloc(void) {
}
result = result && set.keys != set_keys && wpHashSetCapacity(&set) == 8 && wpHashSetCount(&set) == 4;
for (u64 i = 0; i < 3; ++i) {
for (u64 i = 0; i < wpArrayCount(keys); ++i) {
result = result && wpStr8Equal(&wpHashSetItems(WpStr8, &set)[i], &keys[i]);
}
+1
View File
@@ -7,6 +7,7 @@
WpTestFuncResult test_hashset(void);
WpTestFuncResult test_hashset_alloc(void);
WpTestFuncResult test_hashset_get_item_size(void);
WpTestFuncResult test_hashset_find(void);
WpTestFuncResult test_hashset_insert_capped(void);
WpTestFuncResult test_hashset_insert_alloc(void);