diff options
| author | Ben Johnson <benbjohnson@yahoo.com> | 2014-05-07 10:37:50 -0600 |
|---|---|---|
| committer | Ben Johnson <benbjohnson@yahoo.com> | 2014-05-07 10:37:50 -0600 |
| commit | 0966dde0d44d5b42b132e3f2b8e8c6e3dc2c93fe (patch) | |
| tree | 8f876af64e7b40323e71f334a499a347cbb9fcc4 /node.go | |
| parent | Add inline bucket support. (diff) | |
| download | dedo-0966dde0d44d5b42b132e3f2b8e8c6e3dc2c93fe.tar.gz dedo-0966dde0d44d5b42b132e3f2b8e8c6e3dc2c93fe.tar.xz | |
Fix bucket free.
Diffstat (limited to '')
| -rw-r--r-- | node.go | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -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. |
