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

Commit fa946db

Browse files
authored
Merge pull request #2199 from n8sh/core-hash-18924
Fix Issue 18924 - Use addition rather than XOR for order-independent hash combination
2 parents 4a1d176 + dd8bbc7 commit fa946db

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/core/internal/hash.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ size_t hashOf(T)(auto ref T aa, size_t seed = 0) if (!is(T == enum) && __traits(
173173
size_t[2] hpair;
174174
hpair[0] = key.hashOf();
175175
hpair[1] = val.hashOf();
176-
h ^= hpair.hashOf();
176+
h += hpair.hashOf();
177177
}
178178
return h.hashOf(seed);
179179
}

src/rt/aaA.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,8 @@ extern (C) hash_t _aaGetHash(in AA* aa, in TypeInfo tiRaw) nothrow
663663
if (!b.filled)
664664
continue;
665665
size_t[2] h2 = [b.hash, valHash(b.entry + off)];
666-
// use XOR here, so that hash is independent of element order
667-
h ^= hashOf(h2);
666+
// use addition here, so that hash is independent of element order
667+
h += hashOf(h2);
668668
}
669669
return h;
670670
}

0 commit comments

Comments
 (0)