limited scope of closure in btree PutContainerValues

This commit is contained in:
Todd Gruben 2018-01-19 16:03:46 -06:00 • committed by Travis Turner
parent f825bc3b80
commit f5d5cbb0b9
No known key found for this signature in database
GPG key ID: 7F08008DFD9314C9

View file

@ -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) {