Example #1
0
        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"));
        }
Example #2
0
 /// <summary>
 /// Find the entry in the dictionary whose key is the
 /// weak predecessor of the specified key.
 /// </summary>
 /// <param name="key">The key</param>
 /// <param name="res">The predecessor, if any</param>
 /// <returns>True if key has a weak predecessor</returns>
 public bool TryWeakPredecessor(K key, out KeyValuePair <K, V> res)
 {
     return(sortedpairs.TryWeakPredecessor(new KeyValuePair <K, V>(key), out res));
 }
Example #3
0
 /// <summary>
 /// Find the weak predecessor of item in the guarded sorted collection,
 /// that is, the greatest item in the collection smaller than or equal to the item.
 /// </summary>
 /// <param name="item">The item to find the weak predecessor for.</param>
 /// <param name="res">The weak predecessor, if any; otherwise the default value for T.</param>
 /// <returns>True if item has a weak predecessor; otherwise false.</returns>
 public bool TryWeakPredecessor(T item, out T res)
 {
     return(sorted.TryWeakPredecessor(item, out res));
 }