internal static RBUIntNode LowerNode(RBTree tree, uint key) { RBUIntNode lowParent = null; RBUIntNode current = (RBUIntNode)tree.root; while (current != null) { if (key < current.key) { current = (RBUIntNode)current.left; } else if (key > current.key) { lowParent = current; current = (RBUIntNode)current.right; } else { break; } } // we finished walk on a node with key equal to ours if (current != null && current.left != null) { return((RBUIntNode)current.left.LastNode()); } return(lowParent); }
public override void SwapValue(RBTree.Node other) { RBUIntNode node = (RBUIntNode)other; uint tempKey = key; this.key = node.key; node.key = tempKey; T tempValue = this.value; this.value = node.value; node.value = tempValue; }
public override KeyValuePair <uint, T>?Lower(uint key) { XFastTrie <RBTree> .LeafNode separator = Separator(key); if (separator == null) { return(null); } RBUIntNode predNode = RBUtils.LowerNode(separator.value, key); if (predNode == null) { if (separator == cluster.leafList) { return(null); } RBUIntNode highestLeft = (RBUIntNode)((XFastTrie <RBTree> .LeafNode)separator.left).value.LastNode(); return(new KeyValuePair <uint, T>(highestLeft.key, highestLeft.value)); } return(new KeyValuePair <uint, T>(predNode.key, predNode.value)); }
public override KeyValuePair <uint, T>?Higher(uint key) { XFastTrie <RBTree> .LeafNode higherNode = cluster.HigherNode(key); if (higherNode == null) { return(null); } XFastTrie <RBTree> .LeafNode left = (XFastTrie <RBTree> .LeafNode)higherNode.left; if (((XFastTrie <RBTree> .LeafNode)higherNode.left).key == key) { var succNode = (RBUIntNode)higherNode.value.FirstNode(); return(new KeyValuePair <uint, T>(succNode.key, succNode.value)); } RBUIntNode rbHigher = RBUtils.HigherNode(higherNode.value, key); if (rbHigher == null) { return(null); } return(new KeyValuePair <uint, T>(rbHigher.key, rbHigher.value)); }
public override bool TryGetValue(uint key, out T value) { var sep = Separator(key); if (sep == null) { value = default(T); return(false); } RBUIntNode candidate = (RBUIntNode)sep.value.Lookup(key); if (candidate == null) { value = default(T); return(false); } else { value = candidate.value; return(true); } }
private void AddChecked(uint key, T value, bool overwrite) { var separator = Separator(key); if (separator == null) { // add first element RBTree newTree = new RBTree(Node.Helper); newTree.root = new RBUIntNode(key, value) { IsBlack = true }; cluster.Add(BitHacks.MaxValue(cluster.width), newTree); return; } RBUIntNode newNode = new RBUIntNode(key, value); RBUIntNode interned = (RBUIntNode)separator.value.Intern(key, newNode); if (interned != newNode) { if (overwrite) { interned.value = value; } else { throw new ArgumentException(); } } else { count++; version++; } SplitIfTooLarge(separator); }
public override bool Equals(object obj) { RBUIntNode node = obj as RBUIntNode; return((node != null) && (node.key == key) && (Object.Equals(node.value, value))); }