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 /// successor of the specified key. /// </summary> /// <param name="key">The key</param> /// <param name="res">The successor, if any</param> /// <returns>True if the key has a successor</returns> public bool TrySuccessor(K key, out KeyValuePair <K, V> res) { return(sortedpairs.TrySuccessor(new KeyValuePair <K, V>(key), out res)); }
/// <summary> /// Find the strict successor of item in the guarded sorted collection, /// that is, the least item in the collection greater than the supplied value. /// </summary> /// <param name="item">The item to find the successor for.</param> /// <param name="res">The successor, if any; otherwise the default value for T.</param> /// <returns>True if item has a successor; otherwise false.</returns> public bool TrySuccessor(T item, out T res) { return(sorted.TrySuccessor(item, out res)); }