Array changes

This commit is contained in:
2026-07-08 14:24:07 +10:00
parent 378349ebbf
commit e255828a93
4 changed files with 926 additions and 478 deletions
+115 -101
View File
@@ -1,4 +1,4 @@
// Generated by the DN single header generator 2026-07-07 23:09:14
// Generated by the DN single header generator 2026-07-08 14:23:35
// DN: Single header generator commented out => #if defined(_CLANGD)
// #define DN_WITH_TESTS 1
@@ -5966,12 +5966,12 @@ DN_API DN_U64 DN_FNV1AHashU64FromBytes(void const *bytes, DN_USize count, DN_U64
//-----------------------------------------------------------------------------
// Block read - if your platform needs to do endian-swapping or can only
// handle aligned reads, do the conversion here
DN_FORCE_INLINE DN_U32 DN_MurmurHash3GetBlock32_(DN_U32 const *p, int i)
DN_FORCE_INLINE DN_U32 DN_Murmur3GetBlock32_(DN_U32 const *p, int i)
{
return p[i];
}
DN_FORCE_INLINE DN_U64 DN_MurmurHash3GetBlock64_(DN_U64 const *p, int i)
DN_FORCE_INLINE DN_U64 DN_Murmur3GetBlock64_(DN_U64 const *p, int i)
{
return p[i];
}
@@ -5979,7 +5979,7 @@ DN_FORCE_INLINE DN_U64 DN_MurmurHash3GetBlock64_(DN_U64 const *p, int i)
//-----------------------------------------------------------------------------
// Finalization mix - force all bits of a hash block to avalanche
DN_FORCE_INLINE DN_U32 DN_MurmurHash3FMix32_(DN_U32 h)
DN_FORCE_INLINE DN_U32 DN_Murmur3FMix32_(DN_U32 h)
{
h ^= h >> 16;
h *= 0x85ebca6b;
@@ -5989,7 +5989,7 @@ DN_FORCE_INLINE DN_U32 DN_MurmurHash3FMix32_(DN_U32 h)
return h;
}
DN_FORCE_INLINE DN_U64 DN_MurmurHash3FMix64_(DN_U64 k)
DN_FORCE_INLINE DN_U64 DN_Murmur3FMix64_(DN_U64 k)
{
k ^= k >> 33;
k *= 0xff51afd7ed558ccd;
@@ -5999,7 +5999,7 @@ DN_FORCE_INLINE DN_U64 DN_MurmurHash3FMix64_(DN_U64 k)
return k;
}
DN_API DN_U32 DN_MurmurHash3HashU128FromBytesX86(void const *bytes, int len, DN_U32 seed)
DN_API DN_U32 DN_Murmur3HashU128FromBytesX86(void const *bytes, int len, DN_U32 seed)
{
const DN_U8 *data = (const DN_U8 *)bytes;
const int nblocks = len / 4;
@@ -6016,7 +6016,7 @@ DN_API DN_U32 DN_MurmurHash3HashU128FromBytesX86(void const *bytes, int len, DN_
for (int i = -nblocks; i; i++)
{
DN_U32 k1 = DN_MurmurHash3GetBlock32_(blocks, i);
DN_U32 k1 = DN_Murmur3GetBlock32_(blocks, i);
k1 *= c1;
k1 = DN_MMH3_ROTL32(k1, 15);
@@ -6053,12 +6053,12 @@ DN_API DN_U32 DN_MurmurHash3HashU128FromBytesX86(void const *bytes, int len, DN_
h1 ^= len;
h1 = DN_MurmurHash3FMix32_(h1);
h1 = DN_Murmur3FMix32_(h1);
return h1;
}
DN_API DN_MurmurHash3 DN_MurmurHash3HashU128FromBytesX64(void const *bytes, int len, DN_U32 seed)
DN_API DN_Murmur3 DN_Murmur3HashU128FromBytesX64(void const *bytes, int len, DN_U32 seed)
{
const DN_U8 *data = (const DN_U8 *)bytes;
const int nblocks = len / 16;
@@ -6076,8 +6076,8 @@ DN_API DN_MurmurHash3 DN_MurmurHash3HashU128FromBytesX64(void const *bytes, int
for (int i = 0; i < nblocks; i++)
{
DN_U64 k1 = DN_MurmurHash3GetBlock64_(blocks, i * 2 + 0);
DN_U64 k2 = DN_MurmurHash3GetBlock64_(blocks, i * 2 + 1);
DN_U64 k1 = DN_Murmur3GetBlock64_(blocks, i * 2 + 0);
DN_U64 k2 = DN_Murmur3GetBlock64_(blocks, i * 2 + 1);
k1 *= c1;
k1 = DN_MMH3_ROTL64(k1, 31);
@@ -6158,28 +6158,28 @@ DN_API DN_MurmurHash3 DN_MurmurHash3HashU128FromBytesX64(void const *bytes, int
h1 += h2;
h2 += h1;
h1 = DN_MurmurHash3FMix64_(h1);
h2 = DN_MurmurHash3FMix64_(h2);
h1 = DN_Murmur3FMix64_(h1);
h2 = DN_Murmur3FMix64_(h2);
h1 += h2;
h2 += h1;
DN_MurmurHash3 result = {};
DN_Murmur3 result = {};
result.e[0] = h1;
result.e[1] = h2;
return result;
}
DN_API DN_U64 DN_MurmurHash3HashU64FromBytesX64(void const *bytes, int len, DN_U32 seed)
DN_API DN_U64 DN_Murmur3HashU64FromBytesX64(void const *bytes, int len, DN_U32 seed)
{
DN_MurmurHash3 hash = DN_MurmurHash3HashU128FromBytesX64(bytes, len, seed);
DN_Murmur3 hash = DN_Murmur3HashU128FromBytesX64(bytes, len, seed);
DN_U64 result = hash.e[0];
return result;
}
DN_API DN_U32 DN_MurmurHash3HashU32FromBytesX64(void const *bytes, int len, DN_U32 seed)
DN_API DN_U32 DN_Murmur3HashU32FromBytesX64(void const *bytes, int len, DN_U32 seed)
{
DN_MurmurHash3 hash = DN_MurmurHash3HashU128FromBytesX64(bytes, len, seed);
DN_Murmur3 hash = DN_Murmur3HashU128FromBytesX64(bytes, len, seed);
DN_U32 result = DN_Cast(DN_U32)hash.e[0];
return result;
}
@@ -8274,6 +8274,22 @@ DN_API void *DN_ArrayMakeArrayAssert(void *data, DN_USize *count, DN_USize max,
return result;
}
DN_API void *DN_ArrayMakeArrayArena(void **data, DN_USize *count, DN_USize *max, DN_USize elem_size, DN_Arena *arena, DN_USize make_count, DN_ZMem z_mem)
{
void *result = nullptr;
if (DN_ArrayPrepareArena(data, *count, max, elem_size, arena, make_count))
result = DN_ArrayMakeArray(*data, count, *max, elem_size, make_count, z_mem);
return result;
}
DN_API void *DN_ArrayMakeArrayPool(void **data, DN_USize *count, DN_USize *max, DN_USize elem_size, DN_Pool *pool, DN_USize make_count, DN_ZMem z_mem)
{
void *result = nullptr;
if (DN_ArrayPreparePool(data, *count, max, elem_size, pool, make_count))
result = DN_ArrayMakeArray(*data, count, *max, elem_size, make_count, z_mem);
return result;
}
DN_API void *DN_ArrayAddArray(void *data, DN_USize *count, DN_USize max, DN_USize elem_size, void const *elems, DN_USize elems_count, DN_ArrayAdd add)
{
void *result = DN_ArrayMakeArray(data, count, max, elem_size, elems_count, DN_ZMem_No);
@@ -8290,6 +8306,22 @@ DN_API void *DN_ArrayAddArray(void *data, DN_USize *count, DN_USize max, DN_USiz
return result;
}
DN_API void *DN_ArrayAddArrayArena(void **data, DN_USize *count, DN_USize *max, DN_USize elem_size, DN_Arena *arena, void const *elems, DN_USize elems_count, DN_ArrayAdd add)
{
void *result = nullptr;
if (DN_ArrayPrepareArena(data, *count, max, elem_size, arena, elems_count))
result = DN_ArrayAddArray(*data, count, *max, elem_size, elems, elems_count, add);
return result;
}
DN_API void *DN_ArrayAddArrayPool(void **data, DN_USize *count, DN_USize *max, DN_USize elem_size, DN_Pool *pool, void const *elems, DN_USize elems_count, DN_ArrayAdd add)
{
void *result = nullptr;
if (DN_ArrayPreparePool(data, *count, max, elem_size, pool, elems_count))
result = DN_ArrayAddArray(*data, count, *max, elem_size, elems, elems_count, add);
return result;
}
DN_API void *DN_ArrayAddArrayAssert(void *data, DN_USize *count, DN_USize max, DN_USize elem_size, void const *elems, DN_USize elems_count, DN_ArrayAdd add, DN_CallSite call_site)
{
void *result = DN_ArrayAddArray(data, count, max, elem_size, elems, elems_count, add);
@@ -8297,16 +8329,17 @@ DN_API void *DN_ArrayAddArrayAssert(void *data, DN_USize *count, DN_USize max, D
return result;
}
DN_API bool DN_ArrayResizeFromArena(void **data, DN_USize *count, DN_USize *max, DN_USize elem_size, DN_Pool *pool, DN_USize new_max)
static bool DN_ArrayResizeAllocator_(void **data, DN_USize *count, DN_USize *max, DN_USize elem_size, DN_Allocator allocator, DN_USize new_max)
{
bool result = true;
if (!max || new_max != *max) {
DN_USize bytes_to_alloc = elem_size * new_max;
void *buffer = DN_PoolNewArray(pool, DN_U8, bytes_to_alloc);
void *buffer = DN_AllocatorAlloc(allocator, bytes_to_alloc, alignof(DN_UPtr), DN_ZMem_No);
if (buffer) {
DN_USize bytes_to_copy = elem_size * DN_Min(*count, new_max);
DN_Memcpy(buffer, *data, bytes_to_copy);
DN_PoolDealloc(pool, *data);
if (allocator.type == DN_AllocatorType_Pool)
DN_PoolDealloc(DN_Cast(DN_Pool *)allocator.context, *data);
*data = buffer;
*count = DN_Min(*count, new_max);
if (max)
@@ -8319,87 +8352,58 @@ DN_API bool DN_ArrayResizeFromArena(void **data, DN_USize *count, DN_USize *max,
return result;
}
DN_API bool DN_ArrayResizeFromPool(void **data, DN_USize *count, DN_USize *max, DN_USize elem_size, DN_Pool *pool, DN_USize new_max)
DN_API bool DN_ArrayResizeArena(void **data, DN_USize *count, DN_USize *max, DN_USize elem_size, DN_Arena *arena, DN_USize new_max)
{
bool result = true;
if (!max || new_max != *max) {
DN_USize bytes_to_alloc = elem_size * new_max;
void *buffer = DN_PoolNewArray(pool, DN_U8, bytes_to_alloc);
if (buffer) {
DN_USize bytes_to_copy = elem_size * DN_Min(*count, new_max);
DN_Memcpy(buffer, *data, bytes_to_copy);
DN_PoolDealloc(pool, *data);
*data = buffer;
*count = DN_Min(*count, new_max);
if (max)
*max = new_max;
} else {
result = false;
}
}
DN_Allocator allocator = DN_AllocatorFromArena(arena);
bool result = DN_ArrayResizeAllocator_(data, count, max, elem_size, allocator, new_max);
return result;
}
DN_API bool DN_ArrayResizeFromArena(void **data, DN_USize *count, DN_USize *max, DN_USize elem_size, DN_Arena *arena, DN_USize new_max)
DN_API bool DN_ArrayResizePool(void **data, DN_USize *count, DN_USize *max, DN_USize elem_size, DN_Pool *pool, DN_USize new_max)
{
bool result = true;
if (!max || new_max != *max) {
DN_USize bytes_to_alloc = elem_size * new_max;
void *buffer = DN_ArenaNewArray(arena, DN_U8, bytes_to_alloc, DN_ZMem_No);
if (buffer) {
DN_USize bytes_to_copy = elem_size * DN_Min(*count, new_max);
DN_Memcpy(buffer, *data, bytes_to_copy);
*data = buffer;
*count = DN_Min(*count, new_max);
if (max)
*max = new_max;
} else {
result = false;
}
}
DN_Allocator allocator = DN_AllocatorFromPool(pool);
bool result = DN_ArrayResizeAllocator_(data, count, max, elem_size, allocator, new_max);
return result;
}
DN_API bool DN_ArrayGrowFromPool(void **data, DN_USize *max, DN_USize elem_size, DN_Pool *pool, DN_USize new_max)
DN_API bool DN_ArrayReservePool(void **data, DN_USize *max, DN_USize elem_size, DN_Pool *pool, DN_USize new_max)
{
bool result = true;
if (!max || new_max > *max) {
DN_USize count = 0;
result = DN_ArrayResizeFromPool(data, &count, max, elem_size, pool, new_max);
result = DN_ArrayResizePool(data, &count, max, elem_size, pool, new_max);
}
return result;
}
DN_API bool DN_ArrayGrowFromArena(void **data, DN_USize *max, DN_USize elem_size, DN_Arena *arena, DN_USize new_max)
DN_API bool DN_ArrayReserveArena(void **data, DN_USize *max, DN_USize elem_size, DN_Arena *arena, DN_USize new_max)
{
bool result = true;
if (!max || new_max > *max) {
DN_USize count = 0;
result = DN_ArrayResizeFromArena(data, &count, max, elem_size, arena, new_max);
result = DN_ArrayResizeArena(data, &count, max, elem_size, arena, new_max);
}
return result;
}
DN_API bool DN_ArrayGrowIfNeededFromPool(void **data, DN_USize count, DN_USize *max, DN_USize elem_size, DN_Pool *pool, DN_USize add_count)
DN_API bool DN_ArrayPreparePool(void **data, DN_USize count, DN_USize *max, DN_USize elem_size, DN_Pool *pool, DN_USize add_count)
{
bool result = true;
DN_USize new_count = count + add_count;
if (new_count > *max) {
DN_USize new_max = DN_Max(DN_Max(*max * 2, new_count), 8);
result = DN_ArrayResizeFromPool(data, &count, max, elem_size, pool, new_max);
result = DN_ArrayResizePool(data, &count, max, elem_size, pool, new_max);
}
return result;
}
DN_API bool DN_ArrayGrowIfNeededFromArena(void **data, DN_USize count, DN_USize *max, DN_USize elem_size, DN_Arena *arena, DN_USize add_count)
DN_API bool DN_ArrayPrepareArena(void **data, DN_USize count, DN_USize *max, DN_USize elem_size, DN_Arena *arena, DN_USize add_count)
{
bool result = true;
DN_USize new_count = count + add_count;
if (new_count > *max) {
DN_USize new_max = DN_Max(DN_Max(*max * 2, new_count), 8);
result = DN_ArrayResizeFromArena(data, &count, max, elem_size, arena, new_max);
result = DN_ArrayResizeArena(data, &count, max, elem_size, arena, new_max);
}
return result;
}
@@ -8407,7 +8411,7 @@ DN_API bool DN_ArrayGrowIfNeededFromArena(void **data, DN_USize count, DN_USize
DN_API DN_USize DN_ArrayCopyPtrArena(void **data, void const *src, DN_USize count, DN_USize elem_size, DN_Arena *arena)
{
DN_USize result = 0;
if (DN_ArrayGrowFromArena(data, /*max=*/ &result, elem_size, arena, /*new_max=*/ count))
if (DN_ArrayReserveArena(data, /*max=*/ &result, elem_size, arena, /*new_max=*/ count))
DN_Memcpy(*data, src, elem_size * count);
return result;
}
@@ -8422,7 +8426,7 @@ DN_API DN_USize DN_ArrayCopyPtrArenaAssert(void **data, void const *src, DN_USiz
DN_API DN_USize DN_ArrayCopyPtrPool(void **data, void const *src, DN_USize count, DN_USize elem_size, DN_Pool *pool)
{
DN_USize result = 0;
if (DN_ArrayGrowFromPool(data, /*max=*/ &result, elem_size, pool, /*new_max=*/ count))
if (DN_ArrayReservePool(data, /*max=*/ &result, elem_size, pool, /*new_max=*/ count))
DN_Memcpy(*data, src, elem_size * count);
return result;
}
@@ -8488,10 +8492,18 @@ DN_API void DN_RingRead(DN_Ring *ring, void *dest, DN_U64 dest_size)
ring->read_pos += dest_size;
}
DN_API DN_U32 DN_HTableHashFuncDefault(void const *key, DN_USize size)
DN_API DN_U32 DN_HTableHashFuncMurmur3KeyBytes(void const *key, DN_USize size)
{
DN_U32 const DEFAULT_SEED = 0xb255b383;
DN_U32 result = DN_MurmurHash3HashU32FromBytes(key, DN_Cast(int)size, DEFAULT_SEED);
DN_U32 result = DN_Murmur3HashU32FromBytes(key, DN_Cast(int)size, DEFAULT_SEED);
return result;
}
DN_API DN_U32 DN_HTableHashFuncMurmur3KeyStr8(void const *key, DN_USize size)
{
DN_Assert(size == sizeof(DN_Str8));
DN_Str8 *str8_key = DN_Cast(DN_Str8 *)key;
DN_U32 result = DN_HTableHashFuncMurmur3KeyBytes(str8_key->data, str8_key->count);
return result;
}
@@ -8513,7 +8525,7 @@ DN_API DN_HTableInitArgs DN_HTableInitArgsDefault_(void** kvs, DN_USize size_of_
{
DN_HTableInitArgs result = {};
DN_AssertF((*kvs) == 0, "The key-value pointer must be null as the hash table will allocate the objects and keep the pointer in sync with the table for you: %p", *kvs);
result.hash_func = DN_HTableHashFuncDefault;
result.hash_func = DN_HTableHashFuncMurmur3KeyBytes;
result.key_eq_func = DN_HTableKeyEqFuncMemcmp;
result.load_factor = 0.7f;
result.max = 0;
@@ -8615,18 +8627,18 @@ DN_API DN_HTableLookupResult DN_HTableLookup(DN_HTable const *table, void const
DN_Assert(DN_IsPowerOfTwo(table->max));
DN_U32 hash = table->hash_func(key, table->size_of_key);
if (hash < DN_HTableHashSentinel_FirstValid)
if (!DN_HTableHashIsValue(hash))
hash += DN_HTableHashSentinel_FirstValid;
DN_USize const mask = table->max - 1;
DN_USize index = hash & mask;
DN_USize probe_increment = 1;
for (DN_USize offset = 0; offset < table->max; offset++, probe_increment++) {
DN_HTableSlot slot = DN_HTableSlotFromIndex(table, index);
bool matched = slot.hash_u32 == DN_HTableHashSentinel_Empty;
bool matched = DN_HTableSlotIsEmpty(slot);
if (!matched && allow_tombstone == DN_HTableAllowTombstone_Yes)
matched = slot.hash_u32 == DN_HTableHashSentinel_Tomb;
matched = DN_HTableSlotIsTomb(slot);
if (!matched)
matched = slot.hash_u32 >= DN_HTableHashSentinel_FirstValid && slot.hash_u32 == hash && table->key_eq_func(slot.key, key, table->size_of_key);
matched = DN_HTableSlotIsValue(slot) && slot.hash_u32 == hash && table->key_eq_func(slot.key, key, table->size_of_key);
if (matched) {
result.slot = slot;
result.key_hash = hash;
@@ -8646,7 +8658,7 @@ DN_API DN_HTableSlot DN_HTableFind(DN_HTable const *table, void const *key)
{
DN_HTableLookupResult lookup = DN_HTableLookup(table, key, DN_HTableAllowTombstone_No);
DN_HTableSlot result = {};
if (lookup.slot.hash_u32 >= DN_HTableHashSentinel_FirstValid)
if (DN_HTableSlotIsValue(lookup.slot))
result = lookup.slot;
return result;
}
@@ -8689,7 +8701,7 @@ DN_API bool DN_HTableResize(DN_HTable *table, DN_USize new_max)
*table->kvs = new_kvs;
for (DN_ForIndexU(index, old_max)) {
DN_HTableSlot old_slot = DN_HTableSlotFromArgs_(old_kvs, table->size_of_kv, table->offset_of_hash, table->offset_of_key, table->offset_of_value, index);
if (old_slot.hash_u32 >= DN_HTableHashSentinel_FirstValid)
if (DN_HTableSlotIsValue(old_slot))
DN_HTableAdd(table, old_slot.key, old_slot.value);
}
@@ -8705,19 +8717,9 @@ DN_API bool DN_HTableResize(DN_HTable *table, DN_USize new_max)
return result;
}
DN_API void DN_HTableClear(DN_HTable *table)
DN_API DN_HTablePrepareResult DN_HTablePrepare(DN_HTable *table, DN_USize add_count)
{
for (DN_ForIndexU(index, table->max)) {
DN_HTableSlot slot = DN_HTableSlotFromIndex(table, index);
DN_Memset(slot.hash, DN_HTableHashSentinel_Empty, sizeof(slot.hash_u32));
}
table->tombs_count = 0;
table->count = 0;
}
DN_API DN_HTableResizeResult DN_HTableGrowMaybe(DN_HTable *table, DN_USize add_count)
{
DN_HTableResizeResult result = {};
DN_HTablePrepareResult result = {};
result.success = true;
DN_USize new_count = table->count + table->tombs_count + add_count;
DN_F32 new_load_factor = table->max ? new_count / DN_Cast(DN_F32) table->max : table->load_factor01;
@@ -8739,13 +8741,23 @@ DN_API DN_HTableResizeResult DN_HTableGrowMaybe(DN_HTable *table, DN_USize add_c
return result;
}
DN_API void DN_HTableClear(DN_HTable *table)
{
for (DN_ForIndexU(index, table->max)) {
DN_HTableSlot slot = DN_HTableSlotFromIndex(table, index);
DN_Memset(slot.hash, DN_HTableHashSentinel_Empty, sizeof(slot.hash_u32));
}
table->tombs_count = 0;
table->count = 0;
}
DN_API DN_HTableAddResult DN_HTableMake(DN_HTable* table, void* key)
{
// NOTE: First do the lookup ignoring tombstones. This probes the chain looking for the existence
// of the value.
DN_HTableLookupResult lookup = DN_HTableLookup(table, key, DN_HTableAllowTombstone_No);
bool load_factor_is_good = true;
if (lookup.slot.hash_u32 >= DN_HTableHashSentinel_FirstValid) {
if (DN_HTableSlotIsValue(lookup.slot)) {
// NOTE: If it exists, this is the easy path, we can update the slot returned in the lookup.
//
// Note that we do not check if `hash_u32` is the empty value, because that empty value might
@@ -8756,9 +8768,9 @@ DN_API DN_HTableAddResult DN_HTableMake(DN_HTable* table, void* key)
} else {
// NOTE: The value does not exist, look it up again but match on the first tombstone/empty slot
lookup = DN_HTableLookup(table, key, DN_HTableAllowTombstone_Yes);
bool add_will_use_new_slot = lookup.slot.hash_u32 == DN_HTableHashSentinel_Empty;
bool add_will_use_new_slot = DN_HTableSlotIsEmpty(lookup.slot);
if (add_will_use_new_slot) {
DN_HTableResizeResult resize = DN_HTableGrowMaybe(table, 1);
DN_HTablePrepareResult resize = DN_HTablePrepare(table, 1);
if (resize.success)
lookup = DN_HTableLookup(table, key, DN_HTableAllowTombstone_Yes);
else
@@ -8771,9 +8783,9 @@ DN_API DN_HTableAddResult DN_HTableMake(DN_HTable* table, void* key)
if (load_factor_is_good) {
result.success = true;
result.slot = lookup.slot;
if (result.slot.hash_u32 == DN_HTableHashSentinel_Empty) {
if (DN_HTableSlotIsEmpty(result.slot)) {
table->count++;
} else if (result.slot.hash_u32 == DN_HTableHashSentinel_Tomb) {
} else if (DN_HTableSlotIsTomb(result.slot)) {
DN_Assert(table->tombs_count);
table->tombs_count--;
table->count++;
@@ -8806,7 +8818,7 @@ DN_API DN_HTableAddResult DN_HTableAdd(DN_HTable* table, void* key, void* value)
DN_API bool DN_HTableDel(DN_HTable *table, void *key)
{
DN_HTableLookupResult lookup = DN_HTableLookup(table, key, DN_HTableAllowTombstone_No);
bool result = lookup.slot.hash_u32 >= DN_HTableHashSentinel_FirstValid;
bool result = DN_HTableSlotIsValue(lookup.slot);
if (result) {
DN_HTableHashType sentinel = DN_HTableHashSentinel_Tomb;
DN_Memcpy(lookup.slot.hash, &sentinel, sizeof(sentinel));
@@ -9308,7 +9320,7 @@ DN_API DN_TestCore DN_TestInit(DN_Arena *arena)
DN_TestCore result = {};
result.arena = arena;
result.pool = DN_PoolFromArena(arena, DN_POOL_DEFAULT_ALIGN);
DN_PArrayGrowFromPool(result.groups, &result.groups_max, &result.pool, 32);
DN_PArrayReservePool(result.groups, &result.groups_max, &result.pool, 32);
return result;
}
@@ -9316,10 +9328,12 @@ DN_API void DN_TestGroupBeginF(DN_TestCore *test, char const *fmt, ...)
{
DN_AssertF(!test->curr_group, "Previous test group (%.*s) must be ended before starting a new group", DN_Str8PrintFmt(test->curr_group->name));
// NOTE: ALlocate the group
DN_PArrayGrowIfNeededFromPool(test->groups, test->groups_count, &test->groups_max, &test->pool, 1);
// NOTE: Allocate the group
DN_PArrayPreparePool(test->groups, test->groups_count, &test->groups_max, &test->pool, 1);
DN_TestGroup *group = DN_PArrayMakeZ(test->groups, &test->groups_count, test->groups_max);
DN_PArrayGrowFromPool(group->entries, &group->entries_max, &test->pool, 32);
// NOTE: Initially allocate 32 test entries per group
DN_PArrayReservePool(group->entries, &group->entries_max, &test->pool, 32);
// NOTE: Set up the group
va_list args;
@@ -9346,7 +9360,7 @@ DN_API void DN_TestBeginF(DN_TestCore *test, char const *fmt, ...)
// NOTE:Allocate test entry
DN_TestGroup *group = test->curr_group;
DN_PArrayGrowIfNeededFromPool(group->entries, group->entries_count, &group->entries_max, &test->pool, 1);
DN_PArrayPreparePool(group->entries, group->entries_count, &group->entries_max, &test->pool, 1);
DN_AssertF(!group->curr_entry, "Test (%.*s) must be ended before starting another test in the group (%.*s)", DN_Str8PrintFmt(group->curr_entry->name), DN_Str8PrintFmt(group->name));
DN_TestEntry *entry = DN_PArrayMakeZ(group->entries, &group->entries_count, group->entries_max);
@@ -9490,7 +9504,7 @@ DN_API DN_TestDiagnosticRow *DN_TestVerifySetupFmtV(DN_TestCore *test, DN_CallSi
DN_TestEntry *entry = group->curr_entry;
entry->failed = true;
DN_PArrayGrowIfNeededFromPool(entry->diagnostics, entry->diagnostics_count, &entry->diagnostics_max, &test->pool, 1);
DN_PArrayPreparePool(entry->diagnostics, entry->diagnostics_count, &entry->diagnostics_max, &test->pool, 1);
result = DN_PArrayMakeZ(entry->diagnostics, &entry->diagnostics_count, entry->diagnostics_max);
result->expr = expr;
result->call_site = call_site;
@@ -11398,8 +11412,8 @@ DN_API void DN_LeakDump_(DN_LeakTracker *leak)
DN_U64 leak_count = 0;
DN_U64 leaked_bytes = 0;
for (DN_ForItSize(it, DN_LeakTrackerKV, leak->alloc_table_kvs, leak->alloc_table.max)) {
DN_LeakTrackerKV *kv = it.data;
if (kv->hash < DN_HTableHashSentinel_FirstValid)
DN_LeakTrackerKV *kv = it.data;
if (!DN_HTableHashIsValue(kv->hash))
continue;
DN_LeakAlloc *alloc = &kv->value;