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


Golang RangeTreeNode.Black方法代碼示例

本文整理匯總了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
}
開發者ID:cuongdo,項目名稱:cockroach,代碼行數:60,代碼來源:range_tree.go

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


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