2020-10-28 05:16:30 +00:00
|
|
|
#ifndef CTABLE_H
|
|
|
|
#define CTABLE_H
|
|
|
|
|
2023-02-09 18:32:48 +00:00
|
|
|
/* TODO: rewrite this table implementation. compared to other languages (including python!) this
|
|
|
|
* table is verrryyyy slow */
|
2021-01-09 05:53:02 +00:00
|
|
|
|
2020-10-28 05:16:30 +00:00
|
|
|
#include "cosmo.h"
|
|
|
|
#include "cvalue.h"
|
|
|
|
|
2023-02-09 18:32:48 +00:00
|
|
|
typedef struct CTableEntry
|
|
|
|
{
|
2020-10-28 05:16:30 +00:00
|
|
|
CValue key;
|
|
|
|
CValue val;
|
|
|
|
} CTableEntry;
|
|
|
|
|
2023-02-09 18:32:48 +00:00
|
|
|
typedef struct CTable
|
|
|
|
{
|
2020-10-28 05:16:30 +00:00
|
|
|
int count;
|
2021-01-10 20:38:53 +00:00
|
|
|
int capacityMask; // +1 to get the capacity
|
2020-11-17 09:10:55 +00:00
|
|
|
int tombstones;
|
2023-08-26 00:57:16 +00:00
|
|
|
int tombThreshold;
|
2020-10-28 05:16:30 +00:00
|
|
|
CTableEntry *table;
|
|
|
|
} CTable;
|
|
|
|
|
2023-08-26 00:57:16 +00:00
|
|
|
#define cosmoT_getCapacity(tbl) ((tbl)->capacityMask + 1)
|
|
|
|
|
2020-10-28 05:16:30 +00:00
|
|
|
COSMO_API void cosmoT_initTable(CState *state, CTable *tbl, int startCap);
|
|
|
|
COSMO_API void cosmoT_clearTable(CState *state, CTable *tbl);
|
2020-11-30 18:32:04 +00:00
|
|
|
COSMO_API int cosmoT_count(CTable *tbl);
|
2020-10-28 05:16:30 +00:00
|
|
|
|
2020-11-19 20:41:21 +00:00
|
|
|
bool cosmoT_checkShrink(CState *state, CTable *tbl);
|
2021-01-07 23:19:17 +00:00
|
|
|
|
|
|
|
CObjString *cosmoT_lookupString(CTable *tbl, const char *str, int length, uint32_t hash);
|
2021-01-10 20:38:53 +00:00
|
|
|
CValue *cosmoT_insert(CState *state, CTable *tbl, CValue key);
|
2021-02-19 23:04:23 +00:00
|
|
|
bool cosmoT_get(CState *state, CTable *tbl, CValue key, CValue *val);
|
2020-11-17 09:10:55 +00:00
|
|
|
bool cosmoT_remove(CState *state, CTable *tbl, CValue key);
|
2020-10-28 05:16:30 +00:00
|
|
|
|
|
|
|
void cosmoT_printTable(CTable *tbl, const char *name);
|
|
|
|
|
2021-01-02 05:06:24 +00:00
|
|
|
#endif
|