aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
argMaxSet.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
41
54
55// =========================================================================
56#ifndef GUM_ARG_MAX_SET_H
57#define GUM_ARG_MAX_SET_H
58// =========================================================================
59#include <cstdlib>
60// =========================================================================
63
64// =========================================================================
65
66namespace gum {
67
77 template < typename GUM_SCALAR_VAL, typename GUM_SCALAR_SEQ >
78 class ArgMaxSet {
79 public:
80 // ###########################################################################
82 // ###########################################################################
84
85 // ============================================================================
87 // ============================================================================
88 ArgMaxSet();
89
90 // ============================================================================
92 // ============================================================================
93 ArgMaxSet(const GUM_SCALAR_VAL& val, const GUM_SCALAR_SEQ& elem);
94
95 // ============================================================================
97 // ============================================================================
99
102
103 // ============================================================================
105 // ============================================================================
106 ~ArgMaxSet();
107
108 // ============================================================================
110 // ============================================================================
111 void* operator new(size_t s) { return SmallObjectAllocator::instance().allocate(s); }
112
113 void operator delete(void* p) {
115 p,
117 }
118
120
121 // ###########################################################################
123 // ###########################################################################
125
126 // ============================================================================
128 // ============================================================================
130
131 // ============================================================================
133 // ============================================================================
135
137
138 // ###########################################################################
140 // ###########################################################################
142
143 // ============================================================================
145 // ============================================================================
146 ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ >& operator+=(const GUM_SCALAR_SEQ& elem);
147
148 // ============================================================================
150 // ============================================================================
153
154 // ============================================================================
156 // ============================================================================
157 const GUM_SCALAR_SEQ& operator[](const Idx i) const { return _argMaxSeq_->atPos(i); }
158
159 // ============================================================================
161 // ============================================================================
163
165 return !(*this == compared);
166 }
167
168 // ============================================================================
170 // ============================================================================
172 return _val_ < compared.value() ? true : false;
173 }
174
176 return compared < *this;
177 }
178
180 return !(*this > compared);
181 }
182
184 return !(*this < compared);
185 }
186
188
189 // ============================================================================
191 // ============================================================================
192 Idx size() const { return _argMaxSeq_->size(); }
193
194 // ============================================================================
196 // ============================================================================
197 const GUM_SCALAR_VAL& value() const { return _val_; }
198
199 bool exists(const GUM_SCALAR_SEQ& elem) const { return _argMaxSeq_->exists(elem); }
200
201 private:
204 GUM_SCALAR_VAL _val_;
205
206 public:
207 friend std::ostream& operator<<(std::ostream& streamy, const ArgMaxSet& objy) {
208 streamy << "Value : " << objy.value() << " - Set : " << objy._argMaxSeq_->toString();
209 return streamy;
210 }
211 };
212
213} // End of namespace gum
214
216
217#endif /* GUM_ARG_MAX_SET_H */
Outlined implementation of ArgMaxSet.
Class to handle efficiently argMaxSet.
Definition argMaxSet.h:78
bool operator>=(const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ > &compared) const
Ajout d'un élément.
Definition argMaxSet.h:183
~ArgMaxSet()
Destructor.
GUM_SCALAR_VAL _val_
Definition argMaxSet.h:204
Idx size() const
Gives the size.
Definition argMaxSet.h:192
const GUM_SCALAR_VAL & value() const
Returns the value on which comparison are made.
Definition argMaxSet.h:197
friend std::ostream & operator<<(std::ostream &streamy, const ArgMaxSet &objy)
Definition argMaxSet.h:207
bool operator<=(const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ > &compared) const
Ajout d'un élément.
Definition argMaxSet.h:179
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
Ajout d'un élément.
Definition argMaxSet.h:175
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
bool operator!=(const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ > &compared) const
Ajout d'un élément.
Definition argMaxSet.h:164
const GUM_SCALAR_SEQ & operator[](const Idx i) const
Gives the ith element.
Definition argMaxSet.h:157
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
bool operator<(const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ > &compared) const
Checks if val is lower or higher from the compared ArgMaxSet val.
Definition argMaxSet.h:171
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
Header file of gum::Sequence, a class for storing (ordered) sequences of objects.
Headers of gum::SmallObjectAllocator.