public void KeysISortedPred() { ISorted <string> keys = dict.Keys; String res; Assert.IsTrue(keys.TryPredecessor("S", out res)); Assert.AreEqual("R", res); Assert.IsTrue(keys.TryWeakPredecessor("R", out res)); Assert.AreEqual("R", res); Assert.IsTrue(keys.TrySuccessor("S", out res)); Assert.AreEqual("T", res); Assert.IsTrue(keys.TryWeakSuccessor("T", out res)); Assert.AreEqual("T", res); Assert.IsFalse(keys.TryPredecessor("R", out res)); Assert.AreEqual(null, res); Assert.IsFalse(keys.TryWeakPredecessor("P", out res)); Assert.AreEqual(null, res); Assert.IsFalse(keys.TrySuccessor("T", out res)); Assert.AreEqual(null, res); Assert.IsFalse(keys.TryWeakSuccessor("U", out res)); Assert.AreEqual(null, res); Assert.AreEqual("R", keys.Predecessor("S")); Assert.AreEqual("R", keys.WeakPredecessor("R")); Assert.AreEqual("T", keys.Successor("S")); Assert.AreEqual("T", keys.WeakSuccessor("T")); }
/// <summary> /// Find the entry in the dictionary whose key is the /// weak successor of the specified key. /// </summary> /// <param name="key">The key</param> /// <param name="res">The weak successor, if any</param> /// <returns>True if the key has a weak successor</returns> public bool TryWeakSuccessor(K key, out KeyValuePair <K, V> res) { return(sortedpairs.TryWeakSuccessor(new KeyValuePair <K, V>(key), out res)); }
/// <summary> /// Find the weak successor of item in the sorted collection, /// that is, the least item in the collection greater than or equal to the supplied value. /// </summary> /// <param name="item">The item to find the weak successor for.</param> /// <param name="res">The weak successor, if any; otherwise the default value for T.</param> /// <returns>True if item has a weak successor; otherwise false.</returns> public bool TryWeakSuccessor(T item, out T res) { return(sorted.TryWeakSuccessor(item, out res)); }