Updated tests, added panics in btree index.
parent
7f89aac6d1
commit
deefaff7ee
|
@ -1,8 +1,3 @@
|
||||||
# mdb
|
# mdb
|
||||||
|
|
||||||
An in-process, in-memory database for Go.
|
An in-process, in-memory database for Go.
|
||||||
|
|
||||||
## TO DO
|
|
||||||
|
|
||||||
* BTreeIndex:
|
|
||||||
* Panic if insert or update replaces an item
|
|
||||||
|
|
|
@ -118,8 +118,9 @@ func (t *BTreeIndex[T]) Len() int {
|
||||||
func (t *BTreeIndex[T]) insert(item *T) {
|
func (t *BTreeIndex[T]) insert(item *T) {
|
||||||
if t.include == nil || t.include(item) {
|
if t.include == nil || t.include(item) {
|
||||||
t.modify(func(bt *btree.BTreeG[*T]) {
|
t.modify(func(bt *btree.BTreeG[*T]) {
|
||||||
// TODO: Panic if replaces.
|
if _, ok := bt.ReplaceOrInsert(item); ok {
|
||||||
bt.ReplaceOrInsert(item)
|
panic("Insert replaced an item.")
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,8 +131,9 @@ func (t *BTreeIndex[T]) update(old, new *T) {
|
||||||
bt.Delete(old)
|
bt.Delete(old)
|
||||||
}
|
}
|
||||||
if t.include == nil || t.include(new) {
|
if t.include == nil || t.include(new) {
|
||||||
// TODO: Panic if replaces.
|
if _, ok := bt.ReplaceOrInsert(new); ok {
|
||||||
bt.ReplaceOrInsert(new)
|
panic("Update insert replaced an item.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,7 +109,7 @@ func TestShipping(t *testing.T) {
|
||||||
for i := 0; i < 64; i++ {
|
for i := 0; i < 64; i++ {
|
||||||
go func() {
|
go func() {
|
||||||
defer updateWG.Done()
|
defer updateWG.Done()
|
||||||
for j := 0; j < 1024; j++ {
|
for j := 0; j < 4096; j++ {
|
||||||
time.Sleep(sleepTimeout)
|
time.Sleep(sleepTimeout)
|
||||||
db.RandAction()
|
db.RandAction()
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue