Skip to content

Commit

Permalink
stash commutative
Browse files Browse the repository at this point in the history
  • Loading branch information
widlarizer committed Sep 3, 2024
1 parent fd46c7f commit 483f749
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions kernel/hashlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ class Hasher {
*this = hash_ops<T>::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<typename T>
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 483f749

Please sign in to comment.