Skip to content

Commit

Permalink
hashlib: allow forcing Hasher state, use it for IdString trivial hashing
Browse files Browse the repository at this point in the history
  • Loading branch information
widlarizer committed Oct 30, 2024
1 parent 88f0774 commit df44003
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions kernel/hashlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ class Hasher {
state ^= t;
}

void force(hash_t new_state) {
state = new_state;
}

bool is_new() const {
return state == Hasher().state;
}
};

template<typename T>
Expand Down
6 changes: 6 additions & 0 deletions kernel/rtlil.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,12 @@ namespace RTLIL
}

Hasher hash_acc(Hasher h) const {
// If we're starting a hashing sequence, simply start with unhashed ID
if (h.is_new()) {
h.force((Hasher::hash_t) index_);
return h;
}

return hash_ops<int>::hash_acc(index_, h);
}

Expand Down

0 comments on commit df44003

Please sign in to comment.