mirror of
https://github.com/CPunch/Cosmo.git
synced 2024-11-05 08:10:05 +00:00
correctly mark tombstones
This commit is contained in:
parent
1329b72fcd
commit
1189dc4b78
@ -122,7 +122,7 @@ static void resizeTbl(CState *state, CTable *tbl, size_t newCapacity) {
|
|||||||
cosmoM_freearray(state, CTableEntry, entries, newCapacity);
|
cosmoM_freearray(state, CTableEntry, entries, newCapacity);
|
||||||
int tombs = tbl->tombstones;
|
int tombs = tbl->tombstones;
|
||||||
tbl->tombstones = 0;
|
tbl->tombstones = 0;
|
||||||
resizeTbl(state, tbl, nextPow2((tbl->count - tombs) * GROW_FACTOR));
|
resizeTbl(state, tbl, nextPow2((tbl->capacity - tombs) * GROW_FACTOR));
|
||||||
cosmoM_updateThreshhold(state); // force a threshhold update since this *could* be such a huge memory difference
|
cosmoM_updateThreshhold(state); // force a threshhold update since this *could* be such a huge memory difference
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -154,7 +154,6 @@ static void resizeTbl(CState *state, CTable *tbl, size_t newCapacity) {
|
|||||||
tbl->table = entries;
|
tbl->table = entries;
|
||||||
tbl->capacity = newCapacity;
|
tbl->capacity = newCapacity;
|
||||||
tbl->count = newCount;
|
tbl->count = newCount;
|
||||||
tbl->tombstones = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns a pointer to the allocated value
|
// returns a pointer to the allocated value
|
||||||
@ -169,8 +168,11 @@ COSMO_API CValue* cosmoT_insert(CState *state, CTable *tbl, CValue key) {
|
|||||||
// insert into the table
|
// insert into the table
|
||||||
CTableEntry *entry = findEntry(tbl->table, tbl->capacity - 1, key); // -1 for our capacity mask
|
CTableEntry *entry = findEntry(tbl->table, tbl->capacity - 1, key); // -1 for our capacity mask
|
||||||
|
|
||||||
if (IS_NIL(entry->key) && IS_NIL(entry->val)) // is it empty?
|
if (IS_NIL(entry->key))
|
||||||
|
if (IS_NIL(entry->val)) // is it empty?
|
||||||
tbl->count++;
|
tbl->count++;
|
||||||
|
else // it's a tombstone, mark it alive!
|
||||||
|
tbl->tombstones--;
|
||||||
|
|
||||||
entry->key = key;
|
entry->key = key;
|
||||||
return &entry->val;
|
return &entry->val;
|
||||||
|
@ -39,10 +39,10 @@ void printValue(CValue val);
|
|||||||
COSMO_API bool cosmoV_equal(CValue valA, CValue valB);
|
COSMO_API bool cosmoV_equal(CValue valA, CValue valB);
|
||||||
COSMO_API CObjString *cosmoV_toString(CState *state, CValue val);
|
COSMO_API CObjString *cosmoV_toString(CState *state, CValue val);
|
||||||
|
|
||||||
#define IS_NUMBER(x) x.type == COSMO_TNUMBER
|
#define IS_NUMBER(x) (x.type == COSMO_TNUMBER)
|
||||||
#define IS_BOOLEAN(x) x.type == COSMO_TBOOLEAN
|
#define IS_BOOLEAN(x) (x.type == COSMO_TBOOLEAN)
|
||||||
#define IS_NIL(x) x.type == COSMO_TNIL
|
#define IS_NIL(x) (x.type == COSMO_TNIL)
|
||||||
#define IS_OBJ(x) x.type == COSMO_TOBJ
|
#define IS_OBJ(x) (x.type == COSMO_TOBJ)
|
||||||
|
|
||||||
// create CValues
|
// create CValues
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user