diff --git a/README.md b/README.md index fce0ea3..73c4b8d 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,3 @@ # mdb An in-process, in-memory database for Go. - -## TO DO - -* BTreeIndex: - * Panic if insert or update replaces an item diff --git a/btreeindex.go b/btreeindex.go index cb24a95..d2a4f36 100644 --- a/btreeindex.go +++ b/btreeindex.go @@ -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.") + } } }) } diff --git a/shipping_test.go b/shipping_test.go index 6a0077c..7cfd7f7 100644 --- a/shipping_test.go +++ b/shipping_test.go @@ -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() }