當前位置: 首頁>>代碼示例>>Golang>>正文


Golang RangeTreeNode.RightKey方法代碼示例

本文整理匯總了Golang中github.com/cockroachdb/cockroach/proto.RangeTreeNode.RightKey方法的典型用法代碼示例。如果您正苦於以下問題:Golang RangeTreeNode.RightKey方法的具體用法?Golang RangeTreeNode.RightKey怎麽用?Golang RangeTreeNode.RightKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/cockroachdb/cockroach/proto.RangeTreeNode的用法示例。


在下文中一共展示了RangeTreeNode.RightKey方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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

示例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)
}
開發者ID:Hellblazer,項目名稱:cockroach,代碼行數:41,代碼來源:range_tree.go

示例3: 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
	}
	right, err = tc.replaceNode(node, right)
	if err != nil {
		return nil, err
	}
	node.RightKey = right.LeftKey
	if right.LeftKey != nil {
		rightLeft, err := tc.getNode(right.LeftKey)
		if err != nil {
			return nil, err
		}
		rightLeft.ParentKey = node.Key
		tc.setNode(rightLeft)
	}
	right.LeftKey = node.Key
	node.ParentKey = right.Key
	tc.setNode(right)
	tc.setNode(node)
	return right, nil
}
開發者ID:nkhuyu,項目名稱:cockroach,代碼行數:25,代碼來源:range_tree.go


注:本文中的github.com/cockroachdb/cockroach/proto.RangeTreeNode.RightKey方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。