2024-07-19 18:21:40 +01:00
|
|
|
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "Luau/Id.h"
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace Luau::EqSat
|
|
|
|
{
|
|
|
|
|
|
|
|
/// See <https://dl.acm.org/doi/pdf/10.1145/321879.321884>.
|
|
|
|
struct UnionFind final
|
|
|
|
{
|
|
|
|
Id makeSet();
|
|
|
|
Id find(Id id) const;
|
2024-07-26 01:10:42 +01:00
|
|
|
Id find(Id id);
|
2024-11-08 18:43:24 +00:00
|
|
|
|
|
|
|
// Merge aSet with bSet and return the canonicalized Id into the merged set.
|
|
|
|
Id merge(Id aSet, Id bSet);
|
2024-07-19 18:21:40 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<Id> parents;
|
2024-07-26 01:10:42 +01:00
|
|
|
std::vector<int> ranks;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Id canonicalize(Id id) const;
|
2024-07-19 18:21:40 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Luau::EqSat
|