Skip to content

Commit

Permalink
Merge pull request ethereum#640 from ngtuna/nil-node-2
Browse files Browse the repository at this point in the history
fix nil node on RBT
  • Loading branch information
thanhnguyennguyen authored Aug 21, 2019
2 parents 6fe0571 + 34faa2f commit fb6e40a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tomox/orderbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (orderBook *OrderBook) Restore(dryrun bool) error {
log.Error("can't save asks changes to DB", "err", err)
return err
}
log.Debug("restored orderbook asks", "asks.Item", orderBook.Bids.Item)
log.Debug("restored orderbook asks", "asks.Item", orderBook.Asks.Item)

if err := orderBook.Bids.Restore(dryrun); err != nil {
log.Error("can't restore orderbook bids", "err", err)
Expand Down
15 changes: 15 additions & 0 deletions tomox/redblacktree.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,21 @@ func (tree *Tree) Remove(key []byte, dryrun bool) {
child = right
}
if child == nil {
parent := node.Parent(tree, dryrun)
if parent != nil {
if !tree.IsEmptyKey(parent.LeftKey()) && bytes.Equal(parent.LeftKey(), node.Key) {
parent.Item.Keys.Left = EmptyKey()
log.Debug("Set parent.LeftKey() to nil", "parent.Key", parent.Item.Keys)
tree.Save(parent, dryrun)
} else if !tree.IsEmptyKey(parent.RightKey()) && bytes.Equal(parent.RightKey(), node.Key) {
parent.Item.Keys.Right = EmptyKey()
log.Debug("Set parent.RightKey() to nil", "parent.Key", parent.Item.Keys)
tree.Save(parent, dryrun)
} else {
log.Error("Parent doesn't have node as child", "node.Key", hex.EncodeToString(node.Key))
return
}
}
tree.deleteNode(node, dryrun)
log.Debug("Removed node with child = nil", "node", hex.EncodeToString(node.Key), "all keys", tree.KeysinString(true))
} else {
Expand Down

0 comments on commit fb6e40a

Please sign in to comment.