当前位置: 首页>>代码示例>>Golang>>正文


Golang RangeTreeNode.Black方法代码示例

本文整理汇总了Golang中github.com/cockroachdb/cockroach/proto.RangeTreeNode.Black方法的典型用法代码示例。如果您正苦于以下问题:Golang RangeTreeNode.Black方法的具体用法?Golang RangeTreeNode.Black怎么用?Golang RangeTreeNode.Black使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/cockroachdb/cockroach/proto.RangeTreeNode的用法示例。


在下文中一共展示了RangeTreeNode.Black方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 *proto.RangeTreeNode) error {
	key := node.Key
	if node.LeftKey != nil && node.RightKey != nil {
		left, err := tc.getNode(node.LeftKey)
		if err != nil {
			return err
		}
		predecessor, err := tc.getMaxNode(left)
		if err != nil {
			return err
		}
		node, _, err = tc.swapNodes(node, predecessor)
		if err != nil {
			return err
		}
	}

	// Node will always have at most one child.
	var child *proto.RangeTreeNode
	var err error
	if node.LeftKey != nil {
		if child, err = tc.getNode(node.LeftKey); err != nil {
			return err
		}
	} else if node.RightKey != nil {
		if child, err = tc.getNode(node.RightKey); err != nil {
			return err
		}
	}
	if !isRed(node) {
		// Paint the node to the color of the child node.
		node.Black = !isRed(child)
		tc.setNode(node)
		if err := tc.deleteCase1(node); err != nil {
			return err
		}
	}
	if _, err := tc.replaceNode(node, child); err != nil {
		return err
	}

	// Always set the root back to black
	if node, err = tc.getNode(node.Key); err != nil {
		return err
	}
	if child != nil && node.ParentKey == nil {
		if child, err = tc.getNode(child.Key); err != nil {
			return err
		}
		child.Black = true
		tc.setNode(child)
	}

	tc.dropNode(key)
	return nil
}
开发者ID:husttom,项目名称:cockroach,代码行数:60,代码来源:range_tree.go

示例2: insertCase1

// insertCase1 handles the case when the inserted node is the root node.
func (tc *treeContext) insertCase1(node *proto.RangeTreeNode) error {
	if node.ParentKey == nil {
		node.Black = true
		tc.setNode(node)
		return nil
	}
	return tc.insertCase2(node)
}
开发者ID:nkhuyu,项目名称:cockroach,代码行数:9,代码来源:range_tree.go

示例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
	}
	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
}
开发者ID:Hellblazer,项目名称:cockroach,代码行数:17,代码来源:range_tree.go

示例4: rotateLeft

// rotateLeft performs a left rotation around the node.
func (tc *treeContext) rotateLeft(node *proto.RangeTreeNode) (*proto.RangeTreeNode, error) {
	right, err := tc.getNode(node.RightKey)
	if err != nil {
		return nil, err
	}
	if right.Black {
		return nil, util.Error("rotating a black node")
	}
	node.RightKey = right.LeftKey
	right.LeftKey = &node.Key
	right.Black = node.Black
	node.Black = false
	tc.setNode(node)
	tc.setNode(right)
	return right, nil
}
开发者ID:Hellblazer,项目名称:cockroach,代码行数:17,代码来源:range_tree.go

示例5: flip

// flip swaps the color of the node and both of its children. Both those
// children must exist.
func (tc *treeContext) flip(node *proto.RangeTreeNode) (*proto.RangeTreeNode, error) {
	left, err := tc.getNode(node.LeftKey)
	if err != nil {
		return nil, err
	}
	right, err := tc.getNode(node.RightKey)
	if err != nil {
		return nil, err
	}
	node.Black = !node.Black
	left.Black = !left.Black
	right.Black = !right.Black
	tc.setNode(node)
	tc.setNode(left)
	tc.setNode(right)
	return node, nil
}
开发者ID:Hellblazer,项目名称:cockroach,代码行数:19,代码来源:range_tree.go


注:本文中的github.com/cockroachdb/cockroach/proto.RangeTreeNode.Black方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。