/// <summary> /// Convert the elements to type S using the given converter /// </summary> public LobTree <S> Convert <S>(Converter <T, S> converter) where S : IComparable { LobTree <S> result = LobTree <S> .EmptyTree; foreach (T val in this) { bool added; result = LobTree <S> .Insert(result, converter(val), false, out added); } return(result); }
public static LobTree <T> /*?*/ Remove(LobTree <T> t, T o, out bool deleted) //^ ensures result != null ==> !result.Contains(o); //^ ensures deleted ==> result != null && t != null && t.Count = result.Count + 1; { if ((object)t == null) { deleted = false; return(null); } else { Base result = t.representation.Remove(o, HashAlgorithms.GetHashCode(o), 0, out deleted); return(deleted ? new LobTree <T>(result) : t); } }
public static LobTree <T> Insert(LobTree <T> /*?*/ tree, T o, bool replace, out bool added) //^ ensures result.Contains(o); //^ ensures added <==> tree != null && result.Count == tree.Count + 1; //^ ensures added <==> !tree.Contains(o); //^ ensures !added <==> Object.Equals(tree, result); // object equals when o is contained regardless of replace //^ ensures (!added && !replace) <==> ((object)tree == result); // pointer equals iff !replace and !added { int hashKey = HashAlgorithms.GetHashCode(o); if ((object)tree == null) { return(new LobTree <T>(Base.EmptyTree.InsertHelper(o, hashKey, replace, out added, 0))); } else { Base result = tree.representation.InsertHelper(o, hashKey, replace, out added, 0); return(((object)result != (object)(tree.representation)) ? new LobTree <T>(result) : tree); } }