Esempio n. 1
0
 private TreeDictionary <TKey, TValue, TComparer> InsertMax(TKey key, TValue value)
 {
     if (Count == 0)
     {
         return(TreeDictionary.Single <TKey, TValue, TComparer>(key, value));
     }
     return(NearlyBalanced(_left, _right.InsertMax(key, value)));
 }
Esempio n. 2
0
 private static TreeDictionary <TKey, TValue, TComparer> Unbalanced(
     TKey key, TValue value, TreeDictionary <TKey, TValue, TComparer> left, TreeDictionary <TKey, TValue, TComparer> right)
 {
     if (left.Count() == 0)
     {
         return(right.InsertMin(key, value));
     }
     if (right.Count() == 0)
     {
         return(left.InsertMax(key, value));
     }
     if (DELTA * left.Count <= right.Count)
     {
         return(right.NearlyBalanced(Unbalanced(key, value, left, right._left), right._right));
     }
     if (DELTA * right.Count <= left.Count)
     {
         return(left.NearlyBalanced(left._left, Unbalanced(key, value, left._right, right)));
     }
     return(Balanced(key, value, left, right));
 }