本文整理汇总了Golang中github.com/cockroachdb/cockroach/roachpb.RangeTreeNode.Black方法的典型用法代码示例。如果您正苦于以下问题:Golang RangeTreeNode.Black方法的具体用法?Golang RangeTreeNode.Black怎么用?Golang RangeTreeNode.Black使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cockroachdb/cockroach/roachpb.RangeTreeNode
的用法示例。
在下文中一共展示了RangeTreeNode.Black方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: delete
// delete removes a range from the range tree.
// Since this tree is not stored in memory but persisted through the ranges, in
// place deletion is not possible. Instead, we use the helper function
// swapNodes above.
func (tc *treeContext) delete(node *roachpb.RangeTreeNode) *roachpb.Error {
key := node.Key
if node.LeftKey != nil && node.RightKey != nil {
left, pErr := tc.getNode(node.LeftKey)
if pErr != nil {
return pErr
}
predecessor, pErr := tc.getMaxNode(left)
if pErr != nil {
return pErr
}
node, _, pErr = tc.swapNodes(node, predecessor)
if pErr != nil {
return pErr
}
}
// Node will always have at most one child.
var child *roachpb.RangeTreeNode
var pErr *roachpb.Error
if node.LeftKey != nil {
if child, pErr = tc.getNode(node.LeftKey); pErr != nil {
return pErr
}
} else if node.RightKey != nil {
if child, pErr = tc.getNode(node.RightKey); pErr != nil {
return pErr
}
}
if !isRed(node) {
// Paint the node to the color of the child node.
node.Black = !isRed(child)
tc.setNode(node)
if pErr := tc.deleteCase1(node); pErr != nil {
return pErr
}
}
if _, pErr := tc.replaceNode(node, child); pErr != nil {
return pErr
}
// Always set the root back to black
if node, pErr = tc.getNode(node.Key); pErr != nil {
return pErr
}
if child != nil && node.ParentKey == nil {
if child, pErr = tc.getNode(child.Key); pErr != nil {
return pErr
}
child.Black = true
tc.setNode(child)
}
tc.dropNode(key)
return nil
}
示例2: insertCase1
// insertCase1 handles the case when the inserted node is the root node.
func (tc *treeContext) insertCase1(node *roachpb.RangeTreeNode) *roachpb.Error {
if node.ParentKey == nil {
node.Black = true
tc.setNode(node)
return nil
}
return tc.insertCase2(node)
}