Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Fix Issue 18924 - Use addition rather than XOR for order-independent …
Browse files Browse the repository at this point in the history
…hash combination
  • Loading branch information
n8sh committed May 31, 2018
1 parent 335cd2e commit dd8bbc7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/core/internal/hash.d
Expand Up @@ -173,7 +173,7 @@ size_t hashOf(T)(auto ref T aa, size_t seed = 0) if (!is(T == enum) && __traits(
size_t[2] hpair;
hpair[0] = key.hashOf();
hpair[1] = val.hashOf();
h ^= hpair.hashOf();
h += hpair.hashOf();
}
return h.hashOf(seed);
}
Expand Down
4 changes: 2 additions & 2 deletions src/rt/aaA.d
Expand Up @@ -663,8 +663,8 @@ extern (C) hash_t _aaGetHash(in AA* aa, in TypeInfo tiRaw) nothrow
if (!b.filled)
continue;
size_t[2] h2 = [b.hash, valHash(b.entry + off)];
// use XOR here, so that hash is independent of element order
h ^= hashOf(h2);
// use addition here, so that hash is independent of element order
h += hashOf(h2);
}
return h;
}
Expand Down

0 comments on commit dd8bbc7

Please sign in to comment.