Updated tests, added panics in btree index.

master
jdl 2022-07-28 11:23:38 +02:00
parent 7f89aac6d1
commit deefaff7ee
3 changed files with 7 additions and 10 deletions

View File

@ -1,8 +1,3 @@
# mdb
An in-process, in-memory database for Go.
## TO DO
* BTreeIndex:
* Panic if insert or update replaces an item

View File

@ -118,8 +118,9 @@ func (t *BTreeIndex[T]) Len() int {
func (t *BTreeIndex[T]) insert(item *T) {
if t.include == nil || t.include(item) {
t.modify(func(bt *btree.BTreeG[*T]) {
// TODO: Panic if replaces.
bt.ReplaceOrInsert(item)
if _, ok := bt.ReplaceOrInsert(item); ok {
panic("Insert replaced an item.")
}
})
}
}
@ -130,8 +131,9 @@ func (t *BTreeIndex[T]) update(old, new *T) {
bt.Delete(old)
}
if t.include == nil || t.include(new) {
// TODO: Panic if replaces.
bt.ReplaceOrInsert(new)
if _, ok := bt.ReplaceOrInsert(new); ok {
panic("Update insert replaced an item.")
}
}
})
}

View File

@ -109,7 +109,7 @@ func TestShipping(t *testing.T) {
for i := 0; i < 64; i++ {
go func() {
defer updateWG.Done()
for j := 0; j < 1024; j++ {
for j := 0; j < 4096; j++ {
time.Sleep(sleepTimeout)
db.RandAction()
}