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
21
namespace
apollo
{
22
namespace
perception {
23
namespace
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
28
class
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
apollo::perception::algorithm::Universe
Definition
disjoint_set.h:28
apollo::perception::algorithm::Universe::Join
void Join(const int x, const int y)
Definition
disjoint_set.cc:59
apollo::perception::algorithm::Universe::Universe
Universe()=default
apollo::perception::algorithm::Universe::~Universe
~Universe()=default
apollo::perception::algorithm::Universe::Reset
void Reset(const int elements_num)
Definition
disjoint_set.cc:32
apollo::perception::algorithm::Universe::Find
int Find(const int x)
Definition
disjoint_set.cc:42
apollo::perception::algorithm::Universe::GetSetsNum
int GetSetsNum() const
Definition
disjoint_set.h:54
apollo::perception::algorithm::Universe::GetSize
int GetSize(const int x) const
Definition
disjoint_set.h:51
apollo
class register implement
Definition
arena_queue.h:37
modules
perception
common
algorithm
graph
disjoint_set.h