summaryrefslogtreecommitdiff
path: root/Binaries
diff options
context:
space:
mode:
authorGravatar qunyanm <unknown>2015-04-17 13:17:41 -0700
committerGravatar qunyanm <unknown>2015-04-17 13:17:41 -0700
commite4419c2e8d5469787f997fbf0e74f9ef8383c140 (patch)
treeb18c24a280a4532e55f0f2bc426b045312c9eb14 /Binaries
parentcfb9f6a3c00d4943a3bc7248a873b643746e0d24 (diff)
HashCode for Set/MultiSet/Map should be independent of the order of the
elements.
Diffstat (limited to 'Binaries')
-rw-r--r--Binaries/DafnyRuntime.cs18
1 files changed, 10 insertions, 8 deletions
diff --git a/Binaries/DafnyRuntime.cs b/Binaries/DafnyRuntime.cs
index 2a553c81..fd680a0b 100644
--- a/Binaries/DafnyRuntime.cs
+++ b/Binaries/DafnyRuntime.cs
@@ -75,9 +75,9 @@ namespace Dafny
return other is Set<T> && Equals((Set<T>)other);
}
public override int GetHashCode() {
- var hashCode = 0;
+ var hashCode = 1;
foreach (var t in dict.Keys) {
- hashCode = (hashCode << 3) | (hashCode >> 29) ^ t.GetHashCode();
+ hashCode = hashCode * (t.GetHashCode()+3);
}
return hashCode;
}
@@ -232,10 +232,11 @@ namespace Dafny
return other is MultiSet<T> && Equals((MultiSet<T>)other);
}
public override int GetHashCode() {
- var hashCode = 0;
+ var hashCode = 1;
foreach (var kv in dict) {
- hashCode = (hashCode << 3) | (hashCode >> 29) ^ kv.Key.GetHashCode();
- hashCode = (hashCode << 3) | (hashCode >> 29) ^ kv.Value.GetHashCode();
+ var key = kv.Key.GetHashCode();
+ key = (key << 3) | (key >> 29) ^ kv.Value.GetHashCode();
+ hashCode = hashCode * (key + 3);
}
return hashCode;
}
@@ -401,10 +402,11 @@ namespace Dafny
return other is Map<U, V> && Equals((Map<U, V>)other);
}
public override int GetHashCode() {
- var hashCode = 0;
+ var hashCode = 1;
foreach (var kv in dict) {
- hashCode = (hashCode << 3) | (hashCode >> 29) ^ kv.Key.GetHashCode();
- hashCode = (hashCode << 3) | (hashCode >> 29) ^ kv.Value.GetHashCode();
+ var key = kv.Key.GetHashCode();
+ key = (key << 3) | (key >> 29) ^ kv.Value.GetHashCode();
+ hashCode = hashCode * (key + 3);
}
return hashCode;
}