diff --git a/source/toy_table.c b/source/toy_table.c index 67f663f..e665541 100644 --- a/source/toy_table.c +++ b/source/toy_table.c @@ -17,24 +17,15 @@ static void probeAndInsert(Toy_Table** tableHandle, Toy_Value key, Toy_Value val //if we're overriding an existing value if (Toy_checkValuesAreEqual((*tableHandle)->data[probe].key, key)) { (*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; - return; } //if this spot is free, insert and return if (TOY_VALUE_IS_NULL((*tableHandle)->data[probe].key)) { (*tableHandle)->data[probe] = entry; - (*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; - return; } @@ -64,7 +55,6 @@ Toy_Table* Toy_private_adjustTableCapacity(Toy_Table* oldTable, unsigned int new newTable->capacity = newCapacity; newTable->count = 0; - newTable->minPsl = 0; newTable->maxPsl = 0; //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 - for (unsigned int i = (*tableHandle)->minPsl; i < (*tableHandle)->maxPsl; i++) { + for (unsigned int i = 0; i < (*tableHandle)->maxPsl; i++) { //DOOM hack used twice unsigned int p = (probe + i + 0) & ((*tableHandle)->capacity-1); //prev unsigned int u = (probe + i + 1) & ((*tableHandle)->capacity-1); //current diff --git a/source/toy_table.h b/source/toy_table.h index ddd5f5a..df46000 100644 --- a/source/toy_table.h +++ b/source/toy_table.h @@ -14,10 +14,9 @@ typedef struct Toy_TableEntry { //32 | 64 BITNESS typedef struct Toy_Table { //32 | 64 BITNESS unsigned int capacity; //4 | 4 unsigned int count; //4 | 4 - unsigned int minPsl; //4 | 4 unsigned int maxPsl; //4 | 4 Toy_TableEntry data[]; //- | - -} Toy_Table; //16 | 16 +} Toy_Table; //12 | 12 TOY_API Toy_Table* Toy_allocateTable(void); 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); //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_TableEntry* Toy_private_lookupTableEntryPtr(Toy_Table** tableHandle, Toy_Value key); //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); //some useful sizes, could be swapped out as needed #ifndef TOY_TABLE_INITIAL_CAPACITY diff --git a/source/toy_value.h b/source/toy_value.h index b1c3071..996a007 100644 --- a/source/toy_value.h +++ b/source/toy_value.h @@ -33,7 +33,7 @@ typedef struct Toy_Value { //32 | 64 BITNESS bool boolean; //1 | 1 int integer; //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_Table* table; //4 | 8 //TODO: more types go here