From f5d5cbb0b9db8abaa29f1e3828e7f0f33ce37966 Mon Sep 17 00:00:00 2001 From: Todd Gruben Date: Fri, 19 Jan 2018 16:03:46 -0600 Subject: [PATCH] limited scope of closure in btree PutContainerValues --- roaring/containers_btree.go | 40 ++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/roaring/containers_btree.go b/roaring/containers_btree.go index 39e479513..cc0f37a81 100644 --- a/roaring/containers_btree.go +++ b/roaring/containers_btree.go @@ -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) {