Cosmo/src/ctable.h

41 lines
1.1 KiB
C
Raw Normal View History

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;
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);
COSMO_API int cosmoT_count(CTable *tbl);
2020-10-28 05:16:30 +00:00
bool cosmoT_checkShrink(CState *state, CTable *tbl);
CObjString *cosmoT_lookupString(CTable *tbl, const char *str, int length, uint32_t hash);
CValue *cosmoT_insert(CState *state, CTable *tbl, CValue key);
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