aGrUM  0.13.2
argMaxSet.h
Go to the documentation of this file.
1 /*********************************************************************************
2  * Copyright (C) 2005 by Pierre-Henri WUILLEMIN et Christophe GONZALES *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ********************************************************************************/
33 // =========================================================================
34 #ifndef GUM_ARG_MAX_SET_H
35 #define GUM_ARG_MAX_SET_H
36 // =========================================================================
37 #include <cstdlib>
38 // =========================================================================
39 #include <agrum/core/sequence.h>
41 // =========================================================================
42 
43 namespace gum {
44 
53  template < typename GUM_SCALAR_VAL, typename GUM_SCALAR_SEQ >
55  class ArgMaxSet {
56  public:
57  // ###########################################################################
59  // ###########################################################################
61 
62  // ============================================================================
64  // ============================================================================
65  ArgMaxSet();
66 
67  // ============================================================================
69  // ============================================================================
70  ArgMaxSet(const GUM_SCALAR_VAL& val, const GUM_SCALAR_SEQ& elem);
71 
72  // ============================================================================
74  // ============================================================================
76 
79 
80  // ============================================================================
82  // ============================================================================
83  ~ArgMaxSet();
84 
85  // ============================================================================
87  // ============================================================================
88  void* operator new(size_t s) {
90  }
91  void operator delete(void* p) {
94  }
95 
97 
98  // ###########################################################################
100  // ###########################################################################
102 
103  // ============================================================================
105  // ============================================================================
107  return __argMaxSeq->beginSafe();
108  }
109 
110  // ============================================================================
112  // ============================================================================
114  return __argMaxSeq->endSafe();
115  }
116 
118 
119  // ###########################################################################
121  // ###########################################################################
123 
124  // ============================================================================
126  // ============================================================================
128  operator+=(const GUM_SCALAR_SEQ& elem);
129 
130  // ============================================================================
132  // ============================================================================
135 
136  // ============================================================================
138  // ============================================================================
139  const GUM_SCALAR_SEQ& operator[](const Idx i) const {
140  return __argMaxSeq->atPos(i);
141  }
142 
143  // ============================================================================
145  // ============================================================================
146  bool operator==(
147  const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ >& compared) const;
149  const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ >& compared) const {
150  return !(*this == compared);
151  }
152 
153  // ============================================================================
155  // ============================================================================
156  bool operator<(
157  const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ >& compared) const {
158  return __val < compared.value() ? true : false;
159  }
160  bool operator>(
161  const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ >& compared) const {
162  return compared < *this;
163  }
165  const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ >& compared) const {
166  return !(*this > compared);
167  }
169  const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ >& compared) const {
170  return !(*this < compared);
171  }
172 
174 
175  // ============================================================================
177  // ============================================================================
178  Idx size() const { return __argMaxSeq->size(); }
179 
180  // ============================================================================
182  // ============================================================================
183  const GUM_SCALAR_VAL& value() const { return __val; }
184 
185  bool exists(const GUM_SCALAR_SEQ& elem) const {
186  return __argMaxSeq->exists(elem);
187  }
188 
189  private:
192  GUM_SCALAR_VAL __val;
193 
194  public:
195  friend std::ostream& operator<<(std::ostream& streamy, const ArgMaxSet& objy) {
196  streamy << "Value : " << objy.value()
197  << " - Set : " << objy.__argMaxSeq->toString();
198  return streamy;
199  }
200  };
201 
202 } // End of namespace gum
203 
205 
206 #endif /* GUM_ARG_MAX_SET_H */
bool operator>(const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ > &compared) const
Ajout d&#39;un élément.
Definition: argMaxSet.h:160
~ArgMaxSet()
Destructor.
Definition: argMaxSet_tpl.h:82
Headers of gum::SmallObjectAllocator.
const iterator_safe & endSafe() const noexcept
Returns the safe end iterator.
Definition: sequence_tpl.h:630
Header file of gum::Sequence, a class for storing (ordered) sequences of objects. ...
Idx size() const
Gives the size.
Definition: argMaxSet.h:178
bool operator!=(const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ > &compared) const
Ajout d&#39;un élément.
Definition: argMaxSet.h:148
Size size() const noexcept
Returns the size of the sequence.
Definition: sequence_tpl.h:35
bool exists(const GUM_SCALAR_SEQ &elem) const
Definition: argMaxSet.h:185
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:156
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
const Key & atPos(Idx i) const
Returns the object at the pos i.
Definition: sequence_tpl.h:497
Outlined implementation of ArgMaxSet.
Class to handle efficiently argMaxSet.
Definition: argMaxSet.h:55
bool operator<=(const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ > &compared) const
Ajout d&#39;un élément.
Definition: argMaxSet.h:164
bool operator==(const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ > &compared) const
Compares two ArgMaxSet to check if they are equals.
SequenceIteratorSafe< GUM_SCALAR_SEQ > beginSafe() const
Iterator beginning.
Definition: argMaxSet.h:106
std::string toString() const
Displays the content of the sequence.
Definition: sequence_tpl.h:570
iterator_safe beginSafe() const
Returns a safe begin iterator.
Definition: sequence_tpl.h:623
const GUM_SCALAR_VAL & value() const
Returns the value on which comparison are made.
Definition: argMaxSet.h:183
Sequence< GUM_SCALAR_SEQ > * __argMaxSeq
The very bone of the ArgMaxSet.
Definition: argMaxSet.h:191
friend std::ostream & operator<<(std::ostream &streamy, const ArgMaxSet &objy)
Definition: argMaxSet.h:195
void deallocate(void *pDeallocatedObject, const size_t &objectSize)
Deallocates an object.
bool operator>=(const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ > &compared) const
Ajout d&#39;un élément.
Definition: argMaxSet.h:168
ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ > & operator+=(const GUM_SCALAR_SEQ &elem)
Ajout d&#39;un élément.
Definition: argMaxSet_tpl.h:97
bool exists(const Key &k) const
Check the existence of k in the sequence.
Definition: sequence_tpl.h:399
GUM_SCALAR_VAL __val
Definition: argMaxSet.h:192
ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ > & operator=(const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ > &src)
Constructor.
Definition: argMaxSet_tpl.h:71
void * allocate(const size_t &objectSize)
Allocates a block.
static SmallObjectAllocator & instance()
ArgMaxSet()
Constructor.
Definition: argMaxSet_tpl.h:39
unsigned long Idx
Type for indexes.
Definition: types.h:43
const GUM_SCALAR_SEQ & operator[](const Idx i) const
Gives the ith element.
Definition: argMaxSet.h:139
SequenceIteratorSafe< GUM_SCALAR_SEQ > endSafe() const
Iterator end.
Definition: argMaxSet.h:113