本文整理汇总了Golang中github.com/cockroachdb/cockroach/proto.RangeTreeNode.LeftKey方法的典型用法代码示例。如果您正苦于以下问题:Golang RangeTreeNode.LeftKey方法的具体用法?Golang RangeTreeNode.LeftKey怎么用?Golang RangeTreeNode.LeftKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cockroachdb/cockroach/proto.RangeTreeNode
的用法示例。
在下文中一共展示了RangeTreeNode.LeftKey方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: rotateRight
// rotateRight performs a right rotation around the node.
func (tc *treeContext) rotateRight(node *proto.RangeTreeNode) (*proto.RangeTreeNode, error) {
left, err := tc.getNode(node.LeftKey)
if err != nil {
return nil, err
}
if left.Black {
return nil, util.Error("rotating a black node")
}
node.LeftKey = left.RightKey
left.RightKey = &node.Key
left.Black = node.Black
node.Black = false
tc.setNode(node)
tc.setNode(left)
return left, nil
}
示例2: insert
// insert performs the insertion of a new range into the RangeTree. It will
// recursively call insert until it finds the correct location. It will not
// overwrite an already existing key, but that case should not occur.
func (tc *treeContext) insert(node *proto.RangeTreeNode, key proto.Key) (*proto.RangeTreeNode, error) {
if node == nil {
// Insert the new node here.
node = &proto.RangeTreeNode{
Key: key,
}
tc.setNode(node)
} else if key.Less(node.Key) {
// Walk down the tree to the left.
left, err := tc.getNode(node.LeftKey)
if err != nil {
return nil, err
}
left, err = tc.insert(left, key)
if err != nil {
return nil, err
}
if node.LeftKey == nil || !(*node.LeftKey).Equal(left.Key) {
node.LeftKey = &left.Key
tc.setNode(node)
}
} else {
// Walk down the tree to the right.
right, err := tc.getNode(node.RightKey)
if err != nil {
return nil, err
}
right, err = tc.insert(right, key)
if err != nil {
return nil, err
}
if node.RightKey == nil || !(*node.RightKey).Equal(right.Key) {
node.RightKey = &right.Key
tc.setNode(node)
}
}
return tc.walkUpRot23(node)
}
示例3: rotateRight
// rotateRight performs a right rotation around the node.
func (tc *treeContext) rotateRight(node *proto.RangeTreeNode) (*proto.RangeTreeNode, error) {
left, err := tc.getNode(node.LeftKey)
if err != nil {
return nil, err
}
left, err = tc.replaceNode(node, left)
if err != nil {
return nil, err
}
node.LeftKey = left.RightKey
if left.RightKey != nil {
leftRight, err := tc.getNode(left.RightKey)
if err != nil {
return nil, err
}
leftRight.ParentKey = node.Key
tc.setNode(leftRight)
}
left.RightKey = node.Key
node.ParentKey = left.Key
tc.setNode(left)
tc.setNode(node)
return left, nil
}