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); } }
/// <summary> /// Tests whether the given element is found in the collection value. /// </summary> /// <param name="item">The item to find</param> /// <returns>True, if the <paramref name="item"/> is in this collection value, false otherwise.</returns> /// <remarks> /// Complexity: O(log(this.Count)) /// </remarks> public override bool Contains(T item) { T /*?*/ val; return(this.representation.TryGetValue(item, HashAlgorithms.GetHashCode(item), 0, out val)); }
/// <summary> /// Looks up a value associated with a given key /// </summary> /// <param name="o">The key</param> /// <param name="valueFound">The value associated with this key (out parameter), or the default value of type T if not found</param> /// <returns>True if there a value associated with the key was found, false otherwise.</returns> public bool TryGetValue(T o, out T /*?*/ valueFound) //^ ensures result <==> this.Contains(o); //^ ensures !result ==> valueFound == default(T); { return(this.representation.TryGetValue(o, HashAlgorithms.GetHashCode(o), 0, out valueFound)); }