Implemented 'Toy_Table' hashtable with robin hood algorithm, untested

This commit is contained in:
2024-10-03 16:33:47 +10:00
parent a0d616f412
commit 5cf2e70b7d
6 changed files with 266 additions and 2 deletions

27
source/toy_table.h Normal file
View File

@@ -0,0 +1,27 @@
#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** table, Toy_Value key, Toy_Value value);
TOY_API Toy_Value Toy_lookupTableValue(Toy_Table** table, Toy_Value key);
TOY_API void Toy_removeTableEntry(Toy_Table** table, Toy_Value key);