public void testVersusHashMap() { FastByIDMap <String> actual = new FastByIDMap <String>(); IDictionary <long, string> expected = new Dictionary <long, string>(1000000); var r = RandomUtils.getRandom(); for (int i = 0; i < 1000000; i++) { double d = r.nextDouble(); long key = (long)r.nextInt(100); if (d < 0.4) { Assert.AreEqual(expected.ContainsKey(key)?expected[key]:null, actual.Get(key)); } else { if (d < 0.7) { var expectedOldVal = expected.ContainsKey(key) ? expected[key] : null; expected[key] = "bang"; Assert.AreEqual(expectedOldVal, actual.Put(key, "bang")); } else { var expectedOldVal = expected.ContainsKey(key) ? expected[key] : null; expected.Remove(key); Assert.AreEqual(expectedOldVal, actual.Remove(key)); } Assert.AreEqual(expected.Count, actual.Count()); Assert.AreEqual(expected.Count == 0, actual.IsEmpty()); } } }
public void testPutAndGet() { FastByIDMap <long?> map = new FastByIDMap <long?>(); Assert.IsNull(map.Get(500000L)); map.Put(500000L, 2L); Assert.AreEqual(2L, (long)map.Get(500000L)); }
public void testRehash() { FastByIDMap <String> map = buildTestFastMap(); map.Remove(500000L); map.Rehash(); Assert.IsNull(map.Get(500000L)); Assert.AreEqual("bang", map.Get(47L)); }
private static FastByIDMap <String> buildTestFastMap() { FastByIDMap <String> map = new FastByIDMap <String>(); map.Put(500000L, "alpha"); map.Put(47L, "bang"); map.Put(2L, "beta"); return(map); }
public void testGrow() { FastByIDMap <String> map = new FastByIDMap <String>(1, 1); map.Put(500000L, "alpha"); map.Put(47L, "bang"); Assert.IsNull(map.Get(500000L)); Assert.AreEqual("bang", map.Get(47L)); }
public override bool Equals(object other) { if (!(other is FastByIDMap <V>)) { return(false); } FastByIDMap <V> otherMap = (FastByIDMap <V>)other; long[] otherKeys = otherMap.keys; V[] otherValues = otherMap.values; int length = keys.Length; int otherLength = otherKeys.Length; int max = Math.Min(length, otherLength); int i = 0; while (i < max) { long key = keys[i]; long otherKey = otherKeys[i]; if (key == NULL || key == REMOVED) { if (otherKey != NULL && otherKey != REMOVED) { return(false); } } else { if (key != otherKey || !values[i].Equals(otherValues[i])) { return(false); } } i++; } while (i < length) { long key = keys[i]; if (key != NULL && key != REMOVED) { return(false); } i++; } while (i < otherLength) { long key = otherKeys[i]; if (key != NULL && key != REMOVED) { return(false); } i++; } return(true); }
public void testClear() { FastByIDMap <long?> map = new FastByIDMap <long?>(); map.Put(500000L, 2L); map.Clear(); Assert.AreEqual(0, map.Count()); Assert.True(map.IsEmpty()); Assert.IsNull(map.Get(500000L)); }
public void testContains() { FastByIDMap <String> map = buildTestFastMap(); Assert.True(map.ContainsKey(500000L)); Assert.True(map.ContainsKey(47L)); Assert.True(map.ContainsKey(2L)); Assert.True(map.ContainsValue("alpha")); Assert.True(map.ContainsValue("bang")); Assert.True(map.ContainsValue("beta")); Assert.False(map.ContainsKey(999)); Assert.False(map.ContainsValue("something")); }
public void testSizeEmpty() { FastByIDMap <long> map = new FastByIDMap <long>(); Assert.AreEqual(0, map.Count()); Assert.True(map.IsEmpty()); map.Put(500000L, 2L); Assert.AreEqual(1, map.Count()); Assert.False(map.IsEmpty()); map.Remove(500000L); Assert.AreEqual(0, map.Count()); Assert.True(map.IsEmpty()); }
public void testMaxSize() { FastByIDMap <String> map = new FastByIDMap <String>(); map.Put(4, "bang"); Assert.AreEqual(1, map.Count()); map.Put(47L, "bang"); Assert.AreEqual(2, map.Count()); Assert.IsNull(map.Get(500000L)); map.Put(47L, "buzz"); Assert.AreEqual(2, map.Count()); Assert.AreEqual("buzz", map.Get(47L)); }