UnionFind.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @author Tobias Gröger ( tobias dot groeger at student dot kit dot edu )
17  * @author Corvin Navarro ( corvin dot ecker at student dot kit dot edu )
18  * @date 2021
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #pragma once
24 
25 #include <cstddef>
26 #include <cstdint>
27 #include <vector>
28 
30 {
31 
32  // The implementation of this class is taken (and modified) from
33  // https://www.geeksforgeeks.org/disjoint-set-data-structures/
34 
35  /*! \brief A simple union find data structure
36  *
37  * The data structure supports a fixed size of n elements which must be the
38  * integers from [0, n).
39  */
40  class UnionFind
41  {
42  public:
43  /*! \brief Construct a new union find data structure with n elements
44  * \param n the number of elements
45  *
46  * After construction each element will be in its own individual set.
47  */
48  UnionFind(std::size_t n);
49 
50  /*! \brief find the representative of x
51  * \return the representative of x
52  */
53  std::size_t find(std::size_t x);
54 
55  /*! \brief unite the sets of the elements a and b
56  * \param a
57  * \param b
58  */
59  void unite(std::size_t a, std::size_t b);
60 
61  private:
62  std::vector<std::size_t> rank;
63  std::vector<std::size_t> parent;
64  };
65 
66 } // namespace armarx::navigation::components::laser_scanner_feature_extraction
armarx::navigation::components::laser_scanner_feature_extraction::UnionFind::unite
void unite(std::size_t a, std::size_t b)
unite the sets of the elements a and b
Definition: UnionFind.cpp:40
armarx::ctrlutil::a
double a(double t, double a0, double j)
Definition: CtrlUtil.h:45
armarx::navigation::components::laser_scanner_feature_extraction
Definition: ArVizDrawer.cpp:28
armarx::navigation::components::laser_scanner_feature_extraction::UnionFind::UnionFind
UnionFind(std::size_t n)
Construct a new union find data structure with n elements.
Definition: UnionFind.cpp:7
armarx::navigation::components::laser_scanner_feature_extraction::UnionFind::find
std::size_t find(std::size_t x)
find the representative of x
Definition: UnionFind.cpp:19
armarx::navigation::components::laser_scanner_feature_extraction::UnionFind
A simple union find data structure.
Definition: UnionFind.h:40