luau/EqSat/include/Luau/UnionFind.h

30 lines
602 B
C
Raw Normal View History

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);
// 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