public void ContainsKey() { var a = new LruDictionary <int, string>(15); a.Add(1, "one", 3, onRemove: default); a.Add(2, "two", 4, onRemove: default); Assert.IsTrue(a.ContainsKey(1)); Assert.IsTrue(a.ContainsKey(2)); Assert.IsTrue(!a.ContainsKey(3)); a.Remove(1); Assert.IsTrue(!a.ContainsKey(1)); a.Remove(2); Assert.IsTrue(!a.ContainsKey(2)); }
public void GetOrCreate() { var a = new LruDictionary <int, string>(15); var removed = new HashSet <int>(); var s1 = a.GetOrCreate(1, () => ("one", 3), (k, v, s) => removed.Add(1)); Assert.IsTrue(s1 == "one"); Assert.IsTrue(a.Count == 1); Assert.IsTrue(a.ContainsKey(1)); var s1a = a.GetOrCreate(1, () => throw new Exception(), (k, v, s) => removed.Add(-1)); Assert.IsTrue(s1 == "one"); Assert.IsTrue(a.Count == 1); Assert.IsTrue(a.ContainsKey(1)); Assert.IsTrue(a.Remove(1, true)); Assert.IsTrue(removed.Contains(1)); Assert.IsTrue(!removed.Contains(-1)); Assert.IsTrue(a.Count == 0); }
public bool ContainsKey(TK key) { return(_map.ContainsKey(key)); }