mirror of
https://github.com/luau-lang/luau.git
synced 2025-04-03 02:10:53 +01:00
remove const_cast
This commit is contained in:
parent
9b401ae1d6
commit
1cb6973100
2 changed files with 16 additions and 8 deletions
|
@ -19,6 +19,9 @@ struct UnionFind final
|
|||
private:
|
||||
std::vector<Id> parents;
|
||||
std::vector<unsigned int> ranks;
|
||||
|
||||
private:
|
||||
Id canonicalize(Id id) const;
|
||||
};
|
||||
|
||||
} // namespace Luau::EqSat
|
||||
|
|
|
@ -17,20 +17,14 @@ Id UnionFind::makeSet()
|
|||
|
||||
Id UnionFind::find(Id id) const
|
||||
{
|
||||
LUAU_ASSERT(size_t(id) < parents.size());
|
||||
|
||||
// An e-class id 𝑎 is canonical iff find(𝑎) = 𝑎.
|
||||
while (id != parents[size_t(id)])
|
||||
id = parents[size_t(id)];
|
||||
|
||||
return id;
|
||||
return canonicalize(id);
|
||||
}
|
||||
|
||||
Id UnionFind::find(Id id)
|
||||
{
|
||||
LUAU_ASSERT(size_t(id) < parents.size());
|
||||
|
||||
Id set = const_cast<const UnionFind*>(this)->find(id);
|
||||
Id set = canonicalize(id);
|
||||
|
||||
// An e-class id 𝑎 is canonical iff find(𝑎) = 𝑎.
|
||||
while (id != parents[size_t(id)])
|
||||
|
@ -62,4 +56,15 @@ void UnionFind::merge(Id a, Id b)
|
|||
ranks[size_t(aSet)]++;
|
||||
}
|
||||
|
||||
Id UnionFind::canonicalize(Id id) const
|
||||
{
|
||||
LUAU_ASSERT(size_t(id) < parents.size());
|
||||
|
||||
// An e-class id 𝑎 is canonical iff find(𝑎) = 𝑎.
|
||||
while (id != parents[size_t(id)])
|
||||
id = parents[size_t(id)];
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
} // namespace Luau::EqSat
|
||||
|
|
Loading…
Add table
Reference in a new issue