mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
@@ -17,24 +17,15 @@ static void probeAndInsert(Toy_Table** tableHandle, Toy_Value key, Toy_Value val
|
|||||||
//if we're overriding an existing value
|
//if we're overriding an existing value
|
||||||
if (Toy_checkValuesAreEqual((*tableHandle)->data[probe].key, key)) {
|
if (Toy_checkValuesAreEqual((*tableHandle)->data[probe].key, key)) {
|
||||||
(*tableHandle)->data[probe] = entry;
|
(*tableHandle)->data[probe] = entry;
|
||||||
|
|
||||||
//TODO: benchmark the psl optimisation
|
|
||||||
(*tableHandle)->minPsl = entry.psl < (*tableHandle)->minPsl ? entry.psl : (*tableHandle)->minPsl;
|
|
||||||
(*tableHandle)->maxPsl = entry.psl > (*tableHandle)->maxPsl ? entry.psl : (*tableHandle)->maxPsl;
|
(*tableHandle)->maxPsl = entry.psl > (*tableHandle)->maxPsl ? entry.psl : (*tableHandle)->maxPsl;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//if this spot is free, insert and return
|
//if this spot is free, insert and return
|
||||||
if (TOY_VALUE_IS_NULL((*tableHandle)->data[probe].key)) {
|
if (TOY_VALUE_IS_NULL((*tableHandle)->data[probe].key)) {
|
||||||
(*tableHandle)->data[probe] = entry;
|
(*tableHandle)->data[probe] = entry;
|
||||||
|
|
||||||
(*tableHandle)->count++;
|
(*tableHandle)->count++;
|
||||||
|
|
||||||
//TODO: benchmark the psl optimisation
|
|
||||||
(*tableHandle)->minPsl = entry.psl < (*tableHandle)->minPsl ? entry.psl : (*tableHandle)->minPsl;
|
|
||||||
(*tableHandle)->maxPsl = entry.psl > (*tableHandle)->maxPsl ? entry.psl : (*tableHandle)->maxPsl;
|
(*tableHandle)->maxPsl = entry.psl > (*tableHandle)->maxPsl ? entry.psl : (*tableHandle)->maxPsl;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +55,6 @@ Toy_Table* Toy_private_adjustTableCapacity(Toy_Table* oldTable, unsigned int new
|
|||||||
|
|
||||||
newTable->capacity = newCapacity;
|
newTable->capacity = newCapacity;
|
||||||
newTable->count = 0;
|
newTable->count = 0;
|
||||||
newTable->minPsl = 0;
|
|
||||||
newTable->maxPsl = 0;
|
newTable->maxPsl = 0;
|
||||||
|
|
||||||
//unlike other structures, the empty space in a table needs to be null
|
//unlike other structures, the empty space in a table needs to be null
|
||||||
@@ -181,7 +171,7 @@ void Toy_removeTable(Toy_Table** tableHandle, Toy_Value key) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//shift along the later entries
|
//shift along the later entries
|
||||||
for (unsigned int i = (*tableHandle)->minPsl; i < (*tableHandle)->maxPsl; i++) {
|
for (unsigned int i = 0; i < (*tableHandle)->maxPsl; i++) {
|
||||||
//DOOM hack used twice
|
//DOOM hack used twice
|
||||||
unsigned int p = (probe + i + 0) & ((*tableHandle)->capacity-1); //prev
|
unsigned int p = (probe + i + 0) & ((*tableHandle)->capacity-1); //prev
|
||||||
unsigned int u = (probe + i + 1) & ((*tableHandle)->capacity-1); //current
|
unsigned int u = (probe + i + 1) & ((*tableHandle)->capacity-1); //current
|
||||||
|
|||||||
@@ -14,10 +14,9 @@ typedef struct Toy_TableEntry { //32 | 64 BITNESS
|
|||||||
typedef struct Toy_Table { //32 | 64 BITNESS
|
typedef struct Toy_Table { //32 | 64 BITNESS
|
||||||
unsigned int capacity; //4 | 4
|
unsigned int capacity; //4 | 4
|
||||||
unsigned int count; //4 | 4
|
unsigned int count; //4 | 4
|
||||||
unsigned int minPsl; //4 | 4
|
|
||||||
unsigned int maxPsl; //4 | 4
|
unsigned int maxPsl; //4 | 4
|
||||||
Toy_TableEntry data[]; //- | -
|
Toy_TableEntry data[]; //- | -
|
||||||
} Toy_Table; //16 | 16
|
} Toy_Table; //12 | 12
|
||||||
|
|
||||||
TOY_API Toy_Table* Toy_allocateTable(void);
|
TOY_API Toy_Table* Toy_allocateTable(void);
|
||||||
TOY_API void Toy_freeTable(Toy_Table* table);
|
TOY_API void Toy_freeTable(Toy_Table* table);
|
||||||
@@ -26,8 +25,8 @@ TOY_API Toy_Value Toy_lookupTable(Toy_Table** tableHandle, Toy_Value key);
|
|||||||
TOY_API void Toy_removeTable(Toy_Table** tableHandle, Toy_Value key);
|
TOY_API void Toy_removeTable(Toy_Table** tableHandle, Toy_Value key);
|
||||||
|
|
||||||
//NOTE: exposed to skip unnecessary allocations within Toy_Scope
|
//NOTE: exposed to skip unnecessary allocations within Toy_Scope
|
||||||
TOY_API Toy_Table* Toy_private_adjustTableCapacity(Toy_Table* oldTable, unsigned int newCapacity); //TODO: make it public?
|
TOY_API Toy_Table* Toy_private_adjustTableCapacity(Toy_Table* oldTable, unsigned int newCapacity);
|
||||||
TOY_API Toy_TableEntry* Toy_private_lookupTableEntryPtr(Toy_Table** tableHandle, Toy_Value key); //TODO: make it public?
|
TOY_API Toy_TableEntry* Toy_private_lookupTableEntryPtr(Toy_Table** tableHandle, Toy_Value key);
|
||||||
|
|
||||||
//some useful sizes, could be swapped out as needed
|
//some useful sizes, could be swapped out as needed
|
||||||
#ifndef TOY_TABLE_INITIAL_CAPACITY
|
#ifndef TOY_TABLE_INITIAL_CAPACITY
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ typedef struct Toy_Value { //32 | 64 BITNESS
|
|||||||
bool boolean; //1 | 1
|
bool boolean; //1 | 1
|
||||||
int integer; //4 | 4
|
int integer; //4 | 4
|
||||||
float number; //4 | 4
|
float number; //4 | 4
|
||||||
union Toy_String_t* string; //4 | 8
|
union Toy_String_t* string; //4 | 8
|
||||||
struct Toy_Array* array; //4 | 8
|
struct Toy_Array* array; //4 | 8
|
||||||
struct Toy_Table* table; //4 | 8
|
struct Toy_Table* table; //4 | 8
|
||||||
//TODO: more types go here
|
//TODO: more types go here
|
||||||
|
|||||||
Reference in New Issue
Block a user