aGrUM
0.20.3
a C++ library for (probabilistic) graphical models
argMaxSet_tpl.h
Go to the documentation of this file.
1
/**
2
*
3
* Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4
* info_at_agrum_dot_org
5
*
6
* This library is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU Lesser General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
10
*
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU Lesser General Public License for more details.
15
*
16
* You should have received a copy of the GNU Lesser General Public License
17
* along with this library. If not, see <http://www.gnu.org/licenses/>.
18
*
19
*/
20
21
22
/** @file
23
* @brief Outlined implementation of ArgMaxSet
24
*
25
* @author Jean-Christophe MAGNAN
26
*/
27
28
#
include
<
agrum
/
tools
/
core
/
argMaxSet
.
h
>
29
30
31
namespace
gum
{
32
33
// ###########################################################################
34
// CNL
35
// ###########################################################################
36
37
// ============================================================================
38
// Constructor
39
// ============================================================================
40
template
<
typename
GUM_SCALAR_VAL,
typename
GUM_SCALAR_SEQ >
41
ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ >::ArgMaxSet() {
42
GUM_CONSTRUCTOR(ArgMaxSet);
43
_argMaxSeq_ =
new
Sequence< GUM_SCALAR_SEQ >();
44
}
45
46
// ============================================================================
47
// Constructor
48
// ============================================================================
49
template
<
typename
GUM_SCALAR_VAL
,
typename
GUM_SCALAR_SEQ
>
50
ArgMaxSet
<
GUM_SCALAR_VAL
,
GUM_SCALAR_SEQ
>::
ArgMaxSet
(
const
GUM_SCALAR_VAL
&
val
,
51
const
GUM_SCALAR_SEQ
&
elem
) {
52
GUM_CONSTRUCTOR
(
ArgMaxSet
);
53
_argMaxSeq_
=
new
Sequence
<
GUM_SCALAR_SEQ
>();
54
_argMaxSeq_
->
insert
(
elem
);
55
_val_
=
val
;
56
}
57
58
// ============================================================================
59
// Copy Constructor
60
// ============================================================================
61
template
<
typename
GUM_SCALAR_VAL
,
typename
GUM_SCALAR_SEQ
>
62
ArgMaxSet
<
GUM_SCALAR_VAL
,
GUM_SCALAR_SEQ
>::
ArgMaxSet
(
63
const
ArgMaxSet
<
GUM_SCALAR_VAL
,
GUM_SCALAR_SEQ
>&
src
) {
64
GUM_CONS_CPY
(
ArgMaxSet
);
65
_argMaxSeq_
=
new
Sequence
<
GUM_SCALAR_SEQ
>();
66
this
->
operator
+=(
src
);
67
_val_
=
src
.
value
();
68
}
69
70
template
<
typename
GUM_SCALAR_VAL
,
typename
GUM_SCALAR_SEQ
>
71
ArgMaxSet
<
GUM_SCALAR_VAL
,
GUM_SCALAR_SEQ
>&
72
ArgMaxSet
<
GUM_SCALAR_VAL
,
GUM_SCALAR_SEQ
>::
operator
=(
73
const
ArgMaxSet
<
GUM_SCALAR_VAL
,
GUM_SCALAR_SEQ
>&
src
) {
74
this
->
_argMaxSeq_
->
clear
();
75
this
->
operator
+=(
src
);
76
_val_
=
src
.
value
();
77
return
*
this
;
78
}
79
80
// ============================================================================
81
// Destructor
82
// ============================================================================
83
template
<
typename
GUM_SCALAR_VAL
,
typename
GUM_SCALAR_SEQ
>
84
ArgMaxSet
<
GUM_SCALAR_VAL
,
GUM_SCALAR_SEQ
>::~
ArgMaxSet
() {
85
GUM_DESTRUCTOR
(
ArgMaxSet
);
86
delete
_argMaxSeq_
;
87
}
88
89
// ###########################################################################
90
// Operators
91
// ###########################################################################
92
93
// ============================================================================
94
// Ajout d'un élément
95
// ============================================================================
96
template
<
typename
GUM_SCALAR_VAL
,
typename
GUM_SCALAR_SEQ
>
97
ArgMaxSet
<
GUM_SCALAR_VAL
,
GUM_SCALAR_SEQ
>&
98
ArgMaxSet
<
GUM_SCALAR_VAL
,
GUM_SCALAR_SEQ
>::
operator
+=(
const
GUM_SCALAR_SEQ
&
elem
) {
99
_argMaxSeq_
->
insert
(
elem
);
100
return
*
this
;
101
}
102
103
// ============================================================================
104
// Use to insert the content of another set inside this one
105
// ============================================================================
106
template
<
typename
GUM_SCALAR_VAL
,
typename
GUM_SCALAR_SEQ
>
107
ArgMaxSet
<
GUM_SCALAR_VAL
,
GUM_SCALAR_SEQ
>&
108
ArgMaxSet
<
GUM_SCALAR_VAL
,
GUM_SCALAR_SEQ
>::
operator
+=(
109
const
ArgMaxSet
<
GUM_SCALAR_VAL
,
GUM_SCALAR_SEQ
>&
src
) {
110
for
(
auto
iter
=
src
.
beginSafe
();
iter
!=
src
.
endSafe
(); ++
iter
)
111
if
(!
_argMaxSeq_
->
exists
(*
iter
))
_argMaxSeq_
->
insert
(*
iter
);
112
return
*
this
;
113
}
114
115
// ============================================================================
116
// Compares two ArgMaxSet to check if they are equals
117
// ============================================================================
118
template
<
typename
GUM_SCALAR_VAL
,
typename
GUM_SCALAR_SEQ
>
119
bool
ArgMaxSet
<
GUM_SCALAR_VAL
,
GUM_SCALAR_SEQ
>::
operator
==(
120
const
ArgMaxSet
<
GUM_SCALAR_VAL
,
GUM_SCALAR_SEQ
>&
compared
)
const
{
121
if
(
_val_
!=
compared
.
value
())
return
false
;
122
for
(
auto
iter
=
compared
.
beginSafe
();
iter
!=
compared
.
endSafe
(); ++
iter
)
123
if
(!
_argMaxSeq_
->
exists
(*
iter
))
return
false
;
124
for
(
auto
iter
=
this
->
beginSafe
();
iter
!=
this
->
endSafe
(); ++
iter
)
125
if
(!
compared
.
exists
(*
iter
))
return
false
;
126
return
true
;
127
}
128
129
}
// End of namespace gum
gum::Set::emplace
INLINE void emplace(Args &&... args)
Definition:
set_tpl.h:643