public void SimilarHashes() { var sut = HashMap <KeyWithHashCode, int> .Empty; var key1 = new KeyWithHashCode(1, 0x7FFFFFFF); var key2 = new KeyWithHashCode(2, 0x6FFFFFFF); var t = sut.SetItem(key1, 1); t = t.SetItem(key2, 2); t.TryGetValue(key1, out var r1); t.TryGetValue(key2, out var r2); r1.Should().Be(1); r2.Should().Be(2); t = t.Remove(key1); t.Count.Should().Be(1); t.TryGetValue(key1, out r1); t.TryGetValue(key2, out r2); r1.Should().Be(0); r2.Should().Be(2); }
public void HashCollision() { var sut = HashMap <KeyWithHashCode, int> .Empty; var key1 = new KeyWithHashCode(1, 1); var key2 = new KeyWithHashCode(2, 1); var t = sut.SetItem(key1, 1); t = t.SetItem(key2, 2); t.TryGetValue(key1, out var r1); t.TryGetValue(key2, out var r2); r1.Should().Be(1); r2.Should().Be(2); var count = 0; foreach (var x in t) { count++; } count.Should().Be(2); t = t.Remove(key1); t.Count.Should().Be(1); t.TryGetValue(key1, out r1); t.TryGetValue(key2, out r2); r1.Should().Be(0); r2.Should().Be(2); }
public void CreateValuesList() { var rand = new Random(11231992); _keys = new KeyWithHashCode[Size]; for (int i = 0; i < _keys.Length; i++) { _keys[i] = new KeyWithHashCode((ulong)rand.Next(Size / AggCount)); } }