From 0966dde0d44d5b42b132e3f2b8e8c6e3dc2c93fe Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Wed, 7 May 2014 10:37:50 -0600 Subject: Fix bucket free. --- node.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'node.go') diff --git a/node.go b/node.go index 72145c4..1bc889d 100644 --- a/node.go +++ b/node.go @@ -336,7 +336,7 @@ func (n *node) rebalance() { // If root node is a branch and only has one node then collapse it. if !n.isLeaf && len(n.inodes) == 1 { // Move root's child up. - child := n.bucket.nodes[n.inodes[0].pgid] + child := n.bucket.node(n.inodes[0].pgid, n) n.isLeaf = child.isLeaf n.inodes = child.inodes[:] n.children = child.children @@ -357,6 +357,16 @@ func (n *node) rebalance() { return } + // If node has no keys then just remove it. + if n.numChildren() == 0 { + n.parent.del(n.key) + n.parent.removeChild(n) + delete(n.bucket.nodes, n.pgid) + n.free() + n.parent.rebalance() + return + } + _assert(n.parent.numChildren() > 1, "parent must have at least 2 children") // Destination node is right sibling if idx == 0, otherwise left sibling. -- cgit v1.2.3