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 <cstdint>
26 #include <vector>
27 
29 {
30 
31  // The implementation of this class is taken (and modified) from
32  // https://www.geeksforgeeks.org/disjoint-set-data-structures/
33 
34  /*! \brief A simple union find data structure
35  *
36  * The data structure supports a fixed size of n elements which must be the
37  * integers from [0, n).
38  */
39  class UnionFind
40  {
41  public:
42  /*! \brief Construct a new union find data structure with n elements
43  * \param n the number of elements
44  *
45  * After construction each element will be in its own individual set.
46  */
47  UnionFind(std::size_t n);
48 
49  /*! \brief find the representative of x
50  * \return the representative of x
51  */
52  std::size_t find(std::size_t x);
53 
54  /*! \brief unite the sets of the elements a and b
55  * \param a
56  * \param b
57  */
58  void unite(std::size_t a, std::size_t b);
59 
60  private:
61  std::vector<std::size_t> rank;
62  std::vector<std::size_t> parent;
63  };
64 
65 } // 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:38
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:5
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:17
armarx::navigation::components::laser_scanner_feature_extraction::UnionFind
A simple union find data structure.
Definition: UnionFind.h:39