From 483f749bd0774d5399e93fcaee267824d633f67b Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Wed, 21 Aug 2024 23:12:16 +0200 Subject: [PATCH] stash commutative --- kernel/hashlib.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/kernel/hashlib.h b/kernel/hashlib.h index aabd597a139..2d64c359a79 100644 --- a/kernel/hashlib.h +++ b/kernel/hashlib.h @@ -78,6 +78,10 @@ class Hasher { *this = hash_ops::hash_acc(t, *this); } + void commutative_acc(hash_state_t t) { + state ^= t; + } + // Unless they're too big, // hash integers as the size natural to the hasher. template @@ -769,8 +773,10 @@ class dict { Hasher hash_acc(Hasher h) const { h.acc(entries.size()); for (auto &it : entries) { - h.acc(it.udata.first); - h.acc(it.udata.second); + Hasher entry_hash; + entry_hash.acc(it.udata.first); + entry_hash.acc(it.udata.second); + h.commutative_acc(entry_hash.yield()); } return h; } @@ -1136,8 +1142,9 @@ class pool Hasher hash_acc(Hasher h) const { h.acc(entries.size()); - for (auto &it : entries) - h.acc(it.udata); + for (auto &it : entries) { + h.commutative_acc(run_hash(it.udata)); + } return h; }