Apollo 11.0
自动驾驶开放平台
disjoint_set.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
17#pragma once
18
19#include <vector>
20
21namespace apollo {
22namespace perception {
23namespace algorithm {
24
25// Note: a partition of a set U is defined to be a collection P of subsets of U
26// such that U is the union of all sets in P and P is pairwise disjoint. U is
27// called the universe of P and P is a partition of U
28class Universe {
29 struct Element {
30 int rank = 0;
31 int p = 0;
32 int size = 1;
33 };
34
35 public:
36 Universe() = default;
37 explicit Universe(const int elements_num);
38
39 ~Universe() = default;
40
41 // @brief: reset each element
42 void Reset(const int elements_num);
43
44 // @brief: find and return input element's parent
45 int Find(const int x);
46
47 // @brief: join the two elements into one set
48 void Join(const int x, const int y);
49
50 // @brief: get size of input element
51 int GetSize(const int x) const { return elts_[x].size; }
52
53 // @brief: get sets number
54 int GetSetsNum() const { return sets_num_; }
55
56 private:
57 std::vector<Element> elts_;
58 int sets_num_ = 0;
59};
60
61} // namespace algorithm
62} // namespace perception
63} // namespace apollo
void Join(const int x, const int y)
void Reset(const int elements_num)
class register implement
Definition arena_queue.h:37