kernel: Try an order-independent approach to hashing `dict`.

Co-Authored-By: David Shah <dave@ds0.me>
Co-Authored-By: Eddie Hung <eddie@fpgeh.com>
This commit is contained in:
Alberto Gonzalez 2020-05-18 17:10:01 +00:00
parent 976edb7597
commit 6eea4b3d79
No known key found for this signature in database
GPG Key ID: 8395A8BA109708B2
1 changed files with 3 additions and 5 deletions

View File

@ -617,12 +617,10 @@ public:
}
unsigned int hash() const {
std::vector<entry_t> entries_(entries); //make a copy to preserve const-ness
std::sort(entries_.begin(), entries_.end());
unsigned int h = mkhash_init;
for (unsigned int i = 0; i < entries_.size(); ++i) {
h = mkhash(h, hash_ops<K>::hash(entries_[i].udata.first));
h = mkhash(h, hash_ops<T>::hash(entries_[i].udata.second));
for (auto &entry : entries) {
h ^= hash_ops<K>::hash(entry.udata.first);
h ^= hash_ops<T>::hash(entry.udata.second);
}
return h;
}