mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
To help with storing strings within tables, I've replaced the unused '_padding' member of 'Toy_String' with 'cachedHash', which is set to zero on string allocation. The hash of a string isn't generated and stored until it's actually needed, as the rope pattern means not every string needs a hash - hopefully this will save unnecessarily wasted time. When a hash of a string is needed, the hashing function first checks to see if that string already has one, and if so, returns it. Again, less time wasted. When generating a new string hash, the hashing function takes the string's type into account, as node-based strings first need their contents assembled into a simple char buffer. Other changes include: * Changed 'TOY_VALUE_TO_*' to 'TOY_VALUE_FROM_*' * Changed 'TOY_VALUE_IS_EQUAL' to 'TOY_VALUES_ARE_EQUAL' * Added a missing '#pragma once' to 'toy_print.h'
29 lines
976 B
C
29 lines
976 B
C
#pragma once
|
|
|
|
#include "toy_common.h"
|
|
|
|
#include "toy_value.h"
|
|
|
|
//key-value entry, and probe sequence length - https://programming.guide/robin-hood-hashing.html
|
|
typedef struct Toy_TableEntry { //32 | 64 BITNESS
|
|
Toy_Value key; //8 | 8
|
|
Toy_Value value; //8 | 8
|
|
unsigned int psl; //4 | 4
|
|
} Toy_TableEntry; //20 | 20
|
|
|
|
//key-value table (contains = count + tombstones)
|
|
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_API Toy_Table* Toy_allocateTable();
|
|
TOY_API void Toy_freeTable(Toy_Table* table);
|
|
TOY_API void Toy_insertTable(Toy_Table** tableHandle, Toy_Value key, Toy_Value value);
|
|
TOY_API Toy_Value Toy_lookupTable(Toy_Table** tableHandle, Toy_Value key);
|
|
TOY_API void Toy_removeTable(Toy_Table** tableHandle, Toy_Value key);
|
|
|