Skip to content

Commit

Permalink
Removed minPsl from tables, not needed (always zero)
Browse files Browse the repository at this point in the history
Closes #166
  • Loading branch information
Ratstail91 committed Dec 27, 2024
1 parent e96f87f commit 6d25bee
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 16 deletions.
12 changes: 1 addition & 11 deletions source/toy_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions source/toy_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion source/toy_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6d25bee

Please sign in to comment.