public void TestGetAndSet() { CyclingHash hash = new CyclingHash(); hash.Add("A", "a"); hash.Add("B", "b"); hash.Add("C", "c"); Assert.AreEqual(hash.ContainsKey("B"), true); Assert.AreEqual(hash.GetCurrentData(), "C"); Assert.AreEqual(hash.GetValue("A"), "a"); }
/// <summary> /// 添加新缓存 /// </summary> /// <param name="key">关键字</param> /// <param name="value">关键字对应的值</param> /// <param name="overrides">若已存在该关键词,是否覆盖</param> private void SetItem(object key, object value, bool overrides) { if (_table.ContainsKey(key) && !overrides) { return; } _table.Add(key, value); }
public void TestGetKeyByValueChangeValue() { CyclingHash hash = new CyclingHash(); for (int i = 0; i < 1000; i++) { hash.Add(i, i % 10); } List <int> objsA = new List <int>(hash.ReadByValue(9, -1, 10).Cast <int>()); for (int i = 0; i < objsA.Count; i++) { Assert.IsTrue(objsA[i] == 999 - i * 10); } }
public void TestGetKeyByValue() { CyclingHash hash = new CyclingHash(); for (int i = 0; i < 1000; i++) { hash.Add(i, i % 10); } List <int> objs = new List <int>(hash.ReadByValue("2", null, 101).Cast <int>()); for (int i = 0; i < objs.Count; i++) { Assert.IsTrue(objs[i] == 992 - i * 10); } }
public void TestGetKeyByValueChangeValue() { CyclingHash hash = new CyclingHash(); for (int i = 0; i < 1000; i++) { hash.Add(i, i % 10); } List<int> objsA = new List<int>(hash.ReadByValue(9, -1, 10).Cast<int>()); for (int i = 0; i < objsA.Count; i++) { Assert.IsTrue(objsA[i] == 999 - i * 10); } }
public void TestGetKeyByValue() { CyclingHash hash = new CyclingHash(); for (int i = 0; i < 1000; i++) { hash.Add(i, i % 10); } List<int> objs = new List<int>(hash.ReadByValue("2", null, 101).Cast<int>()); for (int i = 0; i < objs.Count; i++) { Assert.IsTrue(objs[i] == 992 - i * 10); } }