TTK
Loading...
Searching...
No Matches
ExtendedUF.h
Go to the documentation of this file.
1
19
20#pragma once
21
22#include <vector>
23
24#include "DeprecatedDataTypes.h"
25
26namespace ttk {
27 namespace cf {
29 private:
30 int rank_;
31 ExtendedUnionFind *parent_;
32 ufDataType data_;
33 SimplexId origin_;
34
35 public:
36 inline ExtendedUnionFind(const SimplexId &origin) {
37 rank_ = 0;
38 parent_ = this;
39 data_ = nullUfData;
40 origin_ = origin;
41 }
42
43 inline ExtendedUnionFind(const ExtendedUnionFind &other) {
44 rank_ = other.rank_;
45 parent_ = this;
46 data_ = other.data_;
47 origin_ = other.origin_;
48 }
49
51 if(&other != this) {
52 rank_ = other.rank_;
53 parent_ = this;
54 data_ = other.data_;
55 origin_ = other.origin_;
56 }
57 return *this;
58 }
59
60 inline void setData(const ufDataType &d) {
61 data_ = d;
62 }
63
64 inline void setOrigin(const SimplexId &origin) {
65 origin_ = origin;
66 }
67
68 inline const ufDataType &getData() const {
69 return data_;
70 }
71
72 inline const SimplexId &getOrigin() const {
73 return origin_;
74 }
75
76 // heavy recursif
78 if(parent_ == this)
79 return this;
80 else {
81 parent_ = parent_->find();
82 return parent_;
83 }
84 }
85
86 inline int getRank() const {
87 return rank_;
88 }
89
90 inline void setParent(ExtendedUnionFind *parent) {
91 parent_ = parent;
92 }
93
94 inline void setRank(const int &rank) {
95 rank_ = rank;
96 }
97
99 ExtendedUnionFind *uf1) {
100 uf0 = uf0->find();
101 uf1 = uf1->find();
102
103 if(uf0 == uf1) {
104 return uf0;
105 } else if(uf0->getRank() > uf1->getRank()) {
106 uf1->setParent(uf0);
107 return uf0;
108 } else if(uf0->getRank() < uf1->getRank()) {
109 uf0->setParent(uf1);
110 return uf1;
111 } else {
112 uf1->setParent(uf0);
113 uf0->setRank(uf0->getRank() + 1);
114 return uf0;
115 }
116 }
117
118 static inline ExtendedUnionFind *
119 makeUnion(std::vector<ExtendedUnionFind *> &sets) {
120 ExtendedUnionFind *n = nullptr;
121
122 if(!sets.size())
123 return nullptr;
124
125 if(sets.size() == 1)
126 return sets[0];
127
128 for(int i = 0; i < (int)sets.size() - 1; i++)
129 n = makeUnion(sets[i], sets[i + 1]);
130
131 return n;
132 }
133
134 inline bool operator<(const ExtendedUnionFind &other) const {
135 return rank_ < other.rank_;
136 }
137
138 inline bool operator>(const ExtendedUnionFind &other) const {
139 return rank_ > other.rank_;
140 }
141 };
142 } // namespace cf
143} // namespace ttk
const ufDataType & getData() const
Definition ExtendedUF.h:68
ExtendedUnionFind(const ExtendedUnionFind &other)
Definition ExtendedUF.h:43
void setData(const ufDataType &d)
Definition ExtendedUF.h:60
void setOrigin(const SimplexId &origin)
Definition ExtendedUF.h:64
void setRank(const int &rank)
Definition ExtendedUF.h:94
const SimplexId & getOrigin() const
Definition ExtendedUF.h:72
bool operator>(const ExtendedUnionFind &other) const
Definition ExtendedUF.h:138
bool operator<(const ExtendedUnionFind &other) const
Definition ExtendedUF.h:134
void setParent(ExtendedUnionFind *parent)
Definition ExtendedUF.h:90
static ExtendedUnionFind * makeUnion(std::vector< ExtendedUnionFind * > &sets)
Definition ExtendedUF.h:119
ExtendedUnionFind & operator=(const ExtendedUnionFind &other)
Definition ExtendedUF.h:50
ExtendedUnionFind(const SimplexId &origin)
Definition ExtendedUF.h:36
static ExtendedUnionFind * makeUnion(ExtendedUnionFind *uf0, ExtendedUnionFind *uf1)
Definition ExtendedUF.h:98
ExtendedUnionFind * find()
Definition ExtendedUF.h:77
long int ufDataType
type stored by UnionFind
The Topology ToolKit.
int SimplexId
Identifier type for simplices of any dimension.
Definition DataTypes.h:22