Fix 'del' on table entries not updating count
This commit is contained in:
parent
6a431e9aa3
commit
abd49b93a7
@ -67,6 +67,7 @@ KrkTableEntry * krk_findEntry(KrkTableEntry * entries, size_t capacity, KrkValue
|
||||
if (IS_NONE(entry->value)) {
|
||||
return tombstone != NULL ? tombstone : entry;
|
||||
} else {
|
||||
if (tombstone == entry) return tombstone;
|
||||
if (tombstone == NULL) tombstone = entry;
|
||||
}
|
||||
} else if (krk_valuesEqual(entry->key, key)) {
|
||||
@ -121,7 +122,7 @@ int krk_tableSet(KrkTable * table, KrkValue key, KrkValue value) {
|
||||
KrkTableEntry * entry = krk_findEntry(table->entries, table->capacity, key);
|
||||
if (!entry) return 0;
|
||||
int isNewKey = IS_KWARGS(entry->key);
|
||||
if (isNewKey && IS_NONE(entry->value)) table->count++;
|
||||
if (isNewKey) table->count++;
|
||||
entry->key = key;
|
||||
entry->value = value;
|
||||
return isNewKey;
|
||||
@ -167,8 +168,9 @@ int krk_tableDelete(KrkTable * table, KrkValue key) {
|
||||
if (!entry || IS_KWARGS(entry->key)) {
|
||||
return 0;
|
||||
}
|
||||
table->count--;
|
||||
entry->key = KWARGS_VAL(0);
|
||||
entry->value = BOOLEAN_VAL(1);
|
||||
entry->value = KWARGS_VAL(0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
44
test/testFullOfTombstones.krk
Normal file
44
test/testFullOfTombstones.krk
Normal file
@ -0,0 +1,44 @@
|
||||
let open = {(0,0)}
|
||||
open.remove( (0, 0) )
|
||||
(1, 0) not in open
|
||||
open.add( (1, 0) )
|
||||
(0, 1) not in open
|
||||
open.add( (0, 1) )
|
||||
open.remove( (0, 1) )
|
||||
(1, 1) not in open
|
||||
open.add( (1, 1) )
|
||||
(0, 2) not in open
|
||||
open.add( (0, 2) )
|
||||
open.remove( (1, 0) )
|
||||
(2, 0) not in open
|
||||
open.add( (2, 0) )
|
||||
open.remove( (2, 0) )
|
||||
(3, 0) not in open
|
||||
open.add( (3, 0) )
|
||||
(2, 1) not in open
|
||||
open.add( (2, 1) )
|
||||
open.remove( (1, 1) )
|
||||
(1, 2) not in open
|
||||
open.add( (1, 2) )
|
||||
open.remove( (0, 2) )
|
||||
(0, 3) not in open
|
||||
open.add( (0, 3) )
|
||||
open.remove( (2, 1) )
|
||||
(3, 1) not in open
|
||||
open.add( (3, 1) )
|
||||
(2, 2) not in open
|
||||
open.add( (2, 2) )
|
||||
open.remove( (3, 0) )
|
||||
(4, 0) not in open
|
||||
open.add( (4, 0) )
|
||||
open.remove( (0, 3) )
|
||||
(1, 3) not in open
|
||||
open.add( (1, 3) )
|
||||
print((0, 4) not in open)
|
||||
open.add( (0, 4) )
|
||||
open.remove( (1, 2) )
|
||||
open.remove( (2, 2) )
|
||||
print((3, 2) not in open)
|
||||
|
||||
|
||||
print("done")
|
3
test/testFullOfTombstones.krk.expect
Normal file
3
test/testFullOfTombstones.krk.expect
Normal file
@ -0,0 +1,3 @@
|
||||
True
|
||||
True
|
||||
done
|
12
test/testTablesDelLen.krk
Normal file
12
test/testTablesDelLen.krk
Normal file
@ -0,0 +1,12 @@
|
||||
|
||||
let d = {1: 2, 3: 4, 5: 6}
|
||||
print(len(d))
|
||||
del d[3]
|
||||
print(len(d))
|
||||
|
||||
let s = {1,2,3}
|
||||
print(len(s))
|
||||
s.remove(2)
|
||||
print(len(s))
|
||||
s.add(2)
|
||||
print(len(s))
|
5
test/testTablesDelLen.krk.expect
Normal file
5
test/testTablesDelLen.krk.expect
Normal file
@ -0,0 +1,5 @@
|
||||
3
|
||||
2
|
||||
3
|
||||
2
|
||||
3
|
Loading…
Reference in New Issue
Block a user