1#ifndef FREE_TENSOR_DISJOINT_SET_H
2#define FREE_TENSOR_DISJOINT_SET_H
5#include <unordered_map>
16 std::unordered_map<T, int> idMap_;
17 std::vector<Node> tree_;
22 while (tree_[root].parent != root)
23 root = tree_[root].parent;
25 while (tree_[
id].parent != root) {
26 auto &p = tree_[id].parent;
33 void uni(
int id0,
int id1) {
34 int root0 = find(id0);
35 int root1 = find(id1);
37 if (tree_[root0].rank < tree_[root1].rank)
38 tree_[root0].parent = root1;
40 tree_[root1].parent = root0;
41 if (tree_[root0].rank == tree_[root1].rank)
47 void add(
const T &key) {
48 if (idMap_.contains(key))
50 auto prev_size = idMap_.size();
51 idMap_.emplace(key, prev_size);
52 tree_.emplace_back(prev_size, 0, key);
56 const T &
find(
const T &key) {
58 return tree_[find(idMap_[key])].key;
61 void uni(
const T &key0,
const T &key1) {
64 uni(idMap_[key0], idMap_[key1]);
Definition: disjoint_set.h:10
void uni(const T &key0, const T &key1)
Definition: disjoint_set.h:61
const T & find(const T &key)
Definition: disjoint_set.h:56
Definition: allocator.h:9