//TODO: Better hash code. Currently same component includemask and includewritemask result in same hashcode public override readonly int GetHashCode() { unchecked { int hashCode = includeMask.GetHashCode(); hashCode = (hashCode * 397) ^ includeWriteMask.GetHashCode(); hashCode = (hashCode * 397) ^ excludeMask.GetHashCode(); hashCode = (hashCode * 397) ^ sharedIncludeMask.GetHashCode(); hashCode = (hashCode * 397) ^ sharedExcludeMask.GetHashCode(); return(hashCode); } }
public void HashCode() { for (int i = 0; i < 256; i++) { for (int j = 0; j < 256; j++) { BitSet256 left = new BitSet256(); BitSet256 right = new BitSet256(); left.Set(i); right.Set(j); int leftHash = left.GetHashCode(); int rightHash = right.GetHashCode(); if (i == j) { Assert.Equal(leftHash, rightHash); } else { Assert.NotEqual(leftHash, rightHash); } } } Random r = new Random(1234); for (int i = 0; i < 1000; i++) { BitSet256 left = new BitSet256(); BitSet256 right = new BitSet256(); for (int j = 0; j < 12; j++) { left.Set(r.Next(0, 256)); right.Set(r.Next(0, 256)); } int leftHash = left.GetHashCode(); int rightHash = right.GetHashCode(); if (left == right) { Assert.Equal(leftHash, rightHash); } else { Assert.NotEqual(leftHash, rightHash); } } }
public int HashCode() { return(bitSet1.GetHashCode()); }