From 38bf0102300c97335d8e78b4683cb9b9476dcde0 Mon Sep 17 00:00:00 2001 From: Fox Caminiti Date: Thu, 10 Nov 2022 22:34:17 -0500 Subject: graph implementation --- memory.cpp | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'memory.cpp') diff --git a/memory.cpp b/memory.cpp index 6e70055..3b3c64f 100644 --- a/memory.cpp +++ b/memory.cpp @@ -34,6 +34,13 @@ Memory_Block_AddressAtIndex(memory *Memory, memory_table_list TableName, uint32 return (void *)Address; } +static uint16 +Memory_Block_IndexAtAddress(memory *Memory, memory_table_list TableName, void *Address) +{ + memory_table *Table = &Memory->Slot[TableName]; + return ((uint8 *)Address - (uint8 *)Table->Address) / Table->Block_ElementSize; +} + static void * Memory_Block_AllocateAddress(memory *Memory, memory_table_list TableName) { @@ -43,7 +50,37 @@ Memory_Block_AllocateAddress(memory *Memory, memory_table_list TableName) // IMPORTANT(fox): All block data has to start with a uint8 Occupied variable! static bool32 -Block_Loop(memory *Memory, memory_table_list TableName, uint32 TotalCount, int *HasIncremented, int *CurrentCount, int *Index) +Block_Loop(memory *Memory, memory_table_list TableName, uint32 TotalCount, int *HasIncremented, int *CurrentCount, int *Index, void *Extra = NULL) +{ + for (;;) { + if (*CurrentCount == TotalCount) { + return 0; + } + if (*HasIncremented) { + *HasIncremented = 0; + (*Index)++; + } + uint8 *Occupied; + if (!Extra) { + Occupied = (uint8 *)Memory_Block_AddressAtIndex(Memory, TableName, *Index); + } else { + Occupied = (uint8 *)Bezier_Lookup(Memory, (property_channel *)Extra, *Index); + } + if (*Occupied) { + *HasIncremented = 1; + (*CurrentCount)++; + return 1; + } + (*Index)++; + Assert(*CurrentCount <= TotalCount); + Assert(*Index <= TotalCount*100); // This can get triggered normally if 100+ items are added and the first 99 in memory are deleted. + } + Assert(0); + return 0; +} + +static bool32 +Block_Loop(memory *Memory, property_channel *Property, uint32 TotalCount, int *HasIncremented, int *CurrentCount, int *Index) { for (;;) { if (*CurrentCount == TotalCount) { @@ -53,7 +90,7 @@ Block_Loop(memory *Memory, memory_table_list TableName, uint32 TotalCount, int * *HasIncremented = 0; (*Index)++; } - uint8 *Occupied = (uint8 *)Memory_Block_AddressAtIndex(Memory, TableName, *Index); + uint8 *Occupied = (uint8 *)Bezier_Lookup(Memory, Property, *Index); if (*Occupied) { *HasIncremented = 1; (*CurrentCount)++; -- cgit v1.2.3