aGrUM 3.1.1
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-2026 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-2026 *
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
41#pragma once
42
43
49
51
52namespace gum {
53
54 // ###########################################################################
55 // CNL
56 // ###########################################################################
57
58 // ============================================================================
59 // Constructor
60 // ============================================================================
61 template < GUM_Numeric GUM_SCALAR_VAL, GUM_Numeric GUM_SCALAR_SEQ >
66
67 // ============================================================================
68 // Constructor
69 // ============================================================================
70 template < GUM_Numeric GUM_SCALAR_VAL, GUM_Numeric GUM_SCALAR_SEQ >
72 const GUM_SCALAR_SEQ& elem) {
73 GUM_CONSTRUCTOR(ArgMaxSet);
75 _argMaxSeq_->insert(elem);
76 _val_ = val;
77 }
78
79 // ============================================================================
80 // Copy Constructor
81 // ============================================================================
82 template < GUM_Numeric GUM_SCALAR_VAL, GUM_Numeric GUM_SCALAR_SEQ >
90
91 template < GUM_Numeric GUM_SCALAR_VAL, GUM_Numeric GUM_SCALAR_SEQ >
95 this->_argMaxSeq_->clear();
96 this->operator+=(src);
97 _val_ = src.value();
98 return *this;
99 }
100
101 // ============================================================================
102 // Destructor
103 // ============================================================================
104 template < GUM_Numeric GUM_SCALAR_VAL, GUM_Numeric GUM_SCALAR_SEQ >
109
110 // ###########################################################################
111 // Operators
112 // ###########################################################################
113
114 // ============================================================================
115 // Ajout d'un élément
116 // ============================================================================
117 template < GUM_Numeric GUM_SCALAR_VAL, GUM_Numeric GUM_SCALAR_SEQ >
120 _argMaxSeq_->insert(elem);
121 return *this;
122 }
123
124 // ============================================================================
125 // Use to insert the content of another set inside this one
126 // ============================================================================
127 template < GUM_Numeric GUM_SCALAR_VAL, GUM_Numeric GUM_SCALAR_SEQ >
131 for (auto iter = src.beginSafe(); iter != src.endSafe(); ++iter)
132 if (!_argMaxSeq_->exists(*iter)) _argMaxSeq_->insert(*iter);
133 return *this;
134 }
135
136 // ============================================================================
137 // Compares two ArgMaxSet to check if they are equals
138 // ============================================================================
139 template < GUM_Numeric GUM_SCALAR_VAL, GUM_Numeric GUM_SCALAR_SEQ >
141 const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ >& compared) const {
142 if (_val_ != compared.value()) return false;
143 for (auto iter = compared.beginSafe(); iter != compared.endSafe(); ++iter)
144 if (!_argMaxSeq_->exists(*iter)) return false;
145 for (auto iter = this->beginSafe(); iter != this->endSafe(); ++iter)
146 if (!compared.exists(*iter)) return false;
147 return true;
148 }
149
150 template < GUM_Numeric GUM_SCALAR_VAL, GUM_Numeric GUM_SCALAR_SEQ >
152 const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ >& compared) const {
153 return _val_ <=> compared.value();
154 }
155
156 template < GUM_Numeric GUM_SCALAR_VAL, GUM_Numeric GUM_SCALAR_SEQ >
160
161 template < GUM_Numeric GUM_SCALAR_VAL, GUM_Numeric GUM_SCALAR_SEQ >
167
168 template < GUM_Numeric GUM_SCALAR_VAL, GUM_Numeric GUM_SCALAR_SEQ >
173
174 template < GUM_Numeric GUM_SCALAR_VAL, GUM_Numeric GUM_SCALAR_SEQ >
179
180 template < GUM_Numeric GUM_SCALAR_VAL, GUM_Numeric GUM_SCALAR_SEQ >
182 return _val_;
183 }
184
185 template < GUM_Numeric GUM_SCALAR_VAL, GUM_Numeric GUM_SCALAR_SEQ >
186 bool ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ >::exists(const GUM_SCALAR_SEQ& elem) const {
187 return _argMaxSeq_->exists(elem);
188 }
189
190 template < GUM_Numeric GUM_SCALAR_VAL, GUM_Numeric GUM_SCALAR_SEQ >
194
195} // 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:182
Idx size() const
Gives the size.
const GUM_SCALAR_VAL & value() const
Returns the value on which comparison are made.
SequenceIteratorSafe< GUM_SCALAR_SEQ > beginSafe() const
Iterator beginning.
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
auto operator<=>(const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ > &compared) const
Ordering comparisons based on val (C++20 spaceship operator).
SequenceIteratorSafe< GUM_SCALAR_SEQ > endSafe() const
Iterator end.
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:181
static SmallObjectAllocator & instance()
void * allocate(const size_t &objectSize)
Allocates a block.
void deallocate(void *pDeallocatedObject, const size_t &objectSize)
Deallocates an object.
Size Idx
Type for indexes.
Definition types.h:79
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.