mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-10-07 03:17:50 +00:00
limited scope of closure in btree PutContainerValues
This commit is contained in:
parent
f825bc3b80
commit
f5d5cbb0b9
1 changed files with 24 additions and 16 deletions
|
|
@ -47,23 +47,31 @@ func (btc *BTreeContainers) Put(key uint64, c *container) {
|
|||
btc.tree.Set(key, c)
|
||||
}
|
||||
|
||||
func (btc *BTreeContainers) PutContainerValues(key uint64, containerType byte, n int, mapped bool) {
|
||||
f := func(oldV *container, exists bool) (*container, bool) {
|
||||
// update the existing container
|
||||
if exists {
|
||||
oldV.containerType = containerType
|
||||
oldV.n = n
|
||||
oldV.mapped = mapped
|
||||
return oldV, true
|
||||
}
|
||||
return &container{
|
||||
containerType: containerType,
|
||||
n: n,
|
||||
mapped: mapped,
|
||||
}, true
|
||||
}
|
||||
type updater struct {
|
||||
key uint64
|
||||
containerType byte
|
||||
n int
|
||||
mapped bool
|
||||
}
|
||||
|
||||
btc.tree.Put(key, f)
|
||||
func (u updater) update(oldV *container, exists bool) (*container, bool) {
|
||||
// update the existing container
|
||||
if exists {
|
||||
oldV.containerType = u.containerType
|
||||
oldV.n = u.n
|
||||
oldV.mapped = u.mapped
|
||||
return oldV, true
|
||||
}
|
||||
return &container{
|
||||
containerType: u.containerType,
|
||||
n: u.n,
|
||||
mapped: u.mapped,
|
||||
}, true
|
||||
}
|
||||
|
||||
func (btc *BTreeContainers) PutContainerValues(key uint64, containerType byte, n int, mapped bool) {
|
||||
a := updater{key, containerType, n, mapped}
|
||||
btc.tree.Put(key, a.update)
|
||||
}
|
||||
|
||||
func (btc *BTreeContainers) Remove(key uint64) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue