added # operator, improved error messages

This commit is contained in:
2020-11-30 12:32:04 -06:00
parent 9dcd1c909a
commit 08c640cd58
13 changed files with 76 additions and 20 deletions

View File

@@ -209,6 +209,11 @@ bool cosmoT_remove(CState* state, CTable *tbl, CValue key) {
return true;
}
// returns the active entry count
COSMO_API int cosmoT_count(CTable *tbl) {
return tbl->count - tbl->tombstones;
}
CObjString *cosmoT_lookupString(CTable *tbl, const char *str, size_t length, uint32_t hash) {
if (tbl->count == 0) return 0; // sanity check
uint32_t indx = hash & (tbl->capacity - 1); // since we know the capacity will *always* be a power of 2, we can use bitwise & to perform a MUCH faster mod operation