private TreeDictionary <TKey, TValue, TComparer> FindAndRemoveMinKeyFromNonEmpty(out TKey minKey, out TValue minKeyValue) { if (_left.Count() == 0) { minKey = _key; minKeyValue = _value; return(_right); } return(NearlyBalanced(_left.FindAndRemoveMinKeyFromNonEmpty(out minKey, out minKeyValue), _right)); }
private static TreeDictionary <TKey, TValue, TComparer> GlueBalanced( TreeDictionary <TKey, TValue, TComparer> left, TreeDictionary <TKey, TValue, TComparer> right) { if (left.Count() == 0) { return(right); } if (right.Count() == 0) { return(left); } TKey minKeyRight; TValue minKeyValueRight; var newRight = right.FindAndRemoveMinKeyFromNonEmpty(out minKeyRight, out minKeyValueRight); return(NearlyBalanced(minKeyRight, minKeyValueRight, left, newRight)); }