hashlib: fixes from jix

This commit is contained in:
Emil J. Tywoniak 2024-11-20 17:06:49 +01:00
parent ed70038aa1
commit 026e9dae9d
4 changed files with 15 additions and 15 deletions

View File

@ -1112,7 +1112,6 @@ private:
bool operator==(const DriveBitId &other) const { return id == other.id; } bool operator==(const DriveBitId &other) const { return id == other.id; }
bool operator!=(const DriveBitId &other) const { return id != other.id; } bool operator!=(const DriveBitId &other) const { return id != other.id; }
bool operator<(const DriveBitId &other) const { return id < other.id; } bool operator<(const DriveBitId &other) const { return id < other.id; }
// unsigned int hash() const { return id; }
Hasher hash_into(Hasher h) const; Hasher hash_into(Hasher h) const;
}; };
// Essentially a dict<DriveBitId, pool<DriveBitId>> but using less memory // Essentially a dict<DriveBitId, pool<DriveBitId>> but using less memory

View File

@ -264,7 +264,11 @@ struct hash_obj_ops {
} }
template<typename T> template<typename T>
static inline Hasher hash_into(const T *a, Hasher h) { static inline Hasher hash_into(const T *a, Hasher h) {
return a ? a->hash_into(h) : h; if (a)
a->hash_into(h);
else
h.eat(0);
return h;
} }
}; };
/** /**
@ -785,13 +789,13 @@ public:
} }
Hasher hash_into(Hasher h) const { Hasher hash_into(Hasher h) const {
h.eat(entries.size());
for (auto &it : entries) { for (auto &it : entries) {
Hasher entry_hash; Hasher entry_hash;
entry_hash.eat(it.udata.first); entry_hash.eat(it.udata.first);
entry_hash.eat(it.udata.second); entry_hash.eat(it.udata.second);
h.commutative_eat(entry_hash.yield()); h.commutative_eat(entry_hash.yield());
} }
h.eat(entries.size());
return h; return h;
} }
@ -1155,10 +1159,10 @@ public:
} }
Hasher hash_into(Hasher h) const { Hasher hash_into(Hasher h) const {
h.eat(entries.size());
for (auto &it : entries) { for (auto &it : entries) {
h.commutative_eat(ops.hash(it.udata).yield()); h.commutative_eat(ops.hash(it.udata).yield());
} }
h.eat(entries.size());
return h; return h;
} }

View File

@ -60,8 +60,6 @@ struct ModIndex : public RTLIL::Monitor
{ {
bool is_input, is_output; bool is_input, is_output;
pool<PortInfo> ports; pool<PortInfo> ports;
// SigBitInfo() : SigBitInfo{} {}
// SigBitInfo& operator=(const SigBitInfo&) = default;
SigBitInfo() : is_input(false), is_output(false) { } SigBitInfo() : is_input(false), is_output(false) { }
@ -310,7 +308,6 @@ struct ModWalker
RTLIL::IdString port; RTLIL::IdString port;
int offset; int offset;
PortBit(Cell* c, IdString p, int o) : cell(c), port(p), offset(o) {} PortBit(Cell* c, IdString p, int o) : cell(c), port(p), offset(o) {}
// PortBit& operator=(const PortBit&) = default;
bool operator<(const PortBit &other) const { bool operator<(const PortBit &other) const {
if (cell != other.cell) if (cell != other.cell)

View File

@ -408,8 +408,14 @@ namespace hashlib {
}; };
}; };
// TODO deprecate this /**
* How to not use these methods:
* 1. if(celltype.in({...})) -> if(celltype.in(...))
* 2. pool<IdString> p; ... a.in(p) -> (bool)p.count(a)
*/
[[deprecated]]
inline bool RTLIL::IdString::in(const pool<IdString> &rhs) const { return rhs.count(*this) != 0; } inline bool RTLIL::IdString::in(const pool<IdString> &rhs) const { return rhs.count(*this) != 0; }
[[deprecated]]
inline bool RTLIL::IdString::in(const pool<IdString> &&rhs) const { return rhs.count(*this) != 0; } inline bool RTLIL::IdString::in(const pool<IdString> &&rhs) const { return rhs.count(*this) != 0; }
namespace RTLIL { namespace RTLIL {
@ -816,7 +822,7 @@ public:
} }
inline Hasher hash_into(Hasher h) const { inline Hasher hash_into(Hasher h) const {
// TODO hash size h.eat(size());
for (auto b : *this) for (auto b : *this)
h.eat(b); h.eat(b);
return h; return h;
@ -1003,12 +1009,6 @@ public:
SigSpec(const std::set<RTLIL::SigBit> &bits); SigSpec(const std::set<RTLIL::SigBit> &bits);
explicit SigSpec(bool bit); explicit SigSpec(bool bit);
[[deprecated]]
size_t get_hash() const {
log_assert(false && "deprecated");
return 0;
}
inline const std::vector<RTLIL::SigChunk> &chunks() const { pack(); return chunks_; } inline const std::vector<RTLIL::SigChunk> &chunks() const { pack(); return chunks_; }
inline const std::vector<RTLIL::SigBit> &bits() const { inline_unpack(); return bits_; } inline const std::vector<RTLIL::SigBit> &bits() const { inline_unpack(); return bits_; }