This really should be an universal reference.

This commit is contained in:
Alexander McCord 2024-05-27 21:11:48 -07:00
parent 994efce30a
commit bf51d9e613

View file

@ -40,11 +40,12 @@ struct EGraph final
return unionfind.find(id); return unionfind.find(id);
} }
// An e-node 𝑛 is canonical iff 𝑛 = canonicalize(𝑛), where template<typename T>
// canonicalize(𝑓(𝑎1, 𝑎2, ...)) = 𝑓(find(𝑎1), find(𝑎2), ...). std::optional<Id> lookup(T&& enode) const
std::optional<Id> lookup(L enode) const
{ {
for (Id& id : enode.operands()) // An e-node 𝑛 is canonical iff 𝑛 = canonicalize(𝑛), where
// canonicalize(𝑓(𝑎1, 𝑎2, ...)) = 𝑓(find(𝑎1), find(𝑎2), ...).
for (Id& id : enode->operands())
id = find(id); id = find(id);
if (auto it = hashcons.find(enode); it != hashcons.end()) if (auto it = hashcons.find(enode); it != hashcons.end())