aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
argMaxSet_tpl.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2025 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40#pragma once
41
42
48
50
51namespace gum {
52
53 // ###########################################################################
54 // CNL
55 // ###########################################################################
56
57 // ============================================================================
58 // Constructor
59 // ============================================================================
60 template < typename GUM_SCALAR_VAL, typename GUM_SCALAR_SEQ >
65
66 // ============================================================================
67 // Constructor
68 // ============================================================================
69 template < typename GUM_SCALAR_VAL, typename GUM_SCALAR_SEQ >
71 const GUM_SCALAR_SEQ& elem) {
72 GUM_CONSTRUCTOR(ArgMaxSet);
74 _argMaxSeq_->insert(elem);
75 _val_ = val;
76 }
77
78 // ============================================================================
79 // Copy Constructor
80 // ============================================================================
81 template < typename GUM_SCALAR_VAL, typename GUM_SCALAR_SEQ >
89
90 template < typename GUM_SCALAR_VAL, typename GUM_SCALAR_SEQ >
94 this->_argMaxSeq_->clear();
95 this->operator+=(src);
96 _val_ = src.value();
97 return *this;
98 }
99
100 // ============================================================================
101 // Destructor
102 // ============================================================================
103 template < typename GUM_SCALAR_VAL, typename GUM_SCALAR_SEQ >
108
109 // ###########################################################################
110 // Operators
111 // ###########################################################################
112
113 // ============================================================================
114 // Ajout d'un élément
115 // ============================================================================
116 template < typename GUM_SCALAR_VAL, typename GUM_SCALAR_SEQ >
119 _argMaxSeq_->insert(elem);
120 return *this;
121 }
122
123 // ============================================================================
124 // Use to insert the content of another set inside this one
125 // ============================================================================
126 template < typename GUM_SCALAR_VAL, typename GUM_SCALAR_SEQ >
130 for (auto iter = src.beginSafe(); iter != src.endSafe(); ++iter)
131 if (!_argMaxSeq_->exists(*iter)) _argMaxSeq_->insert(*iter);
132 return *this;
133 }
134
135 // ============================================================================
136 // Compares two ArgMaxSet to check if they are equals
137 // ============================================================================
138 template < typename GUM_SCALAR_VAL, typename GUM_SCALAR_SEQ >
140 const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ >& compared) const {
141 if (_val_ != compared.value()) return false;
142 for (auto iter = compared.beginSafe(); iter != compared.endSafe(); ++iter)
143 if (!_argMaxSeq_->exists(*iter)) return false;
144 for (auto iter = this->beginSafe(); iter != this->endSafe(); ++iter)
145 if (!compared.exists(*iter)) return false;
146 return true;
147 }
148
149} // End of namespace gum
This files contains several function objects that are not (yet) defined in the STL.
Class to handle efficiently argMaxSet.
Definition argMaxSet.h:78
~ArgMaxSet()
Destructor.
GUM_SCALAR_VAL _val_
Definition argMaxSet.h:204
const GUM_SCALAR_VAL & value() const
Returns the value on which comparison are made.
Definition argMaxSet.h:197
SequenceIteratorSafe< GUM_SCALAR_SEQ > beginSafe() const
Iterator beginning.
Definition argMaxSet.h:129
ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ > & operator=(const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ > &src)
Constructor.
bool operator==(const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ > &compared) const
Compares two ArgMaxSet to check if they are equals.
bool exists(const GUM_SCALAR_SEQ &elem) const
Definition argMaxSet.h:199
SequenceIteratorSafe< GUM_SCALAR_SEQ > endSafe() const
Iterator end.
Definition argMaxSet.h:134
ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ > & operator+=(const GUM_SCALAR_SEQ &elem)
Ajout d'un élément.
ArgMaxSet()
Constructor.
Sequence< GUM_SCALAR_SEQ > * _argMaxSeq_
The very bone of the ArgMaxSet.
Definition argMaxSet.h:203
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
HashTableIteratorSafe< Key, Val > & operator+=(Size i) noexcept
Makes the iterator point to i elements further in the hashtable.