mirror of
https://github.com/luau-lang/luau.git
synced 2024-11-15 14:25:44 +08:00
2874ca9e86
Implements ranks & path compression for union find. --------- Co-authored-by: Alexander McCord <11488393+alexmccord@users.noreply.github.com>
28 lines
516 B
C++
28 lines
516 B
C++
// 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;
|
|
Id find(Id id);
|
|
void merge(Id a, Id b);
|
|
|
|
private:
|
|
std::vector<Id> parents;
|
|
std::vector<int> ranks;
|
|
|
|
private:
|
|
Id canonicalize(Id id) const;
|
|
};
|
|
|
|
} // namespace Luau::EqSat
|