aGrUM  0.16.0
argMaxSet.h
Go to the documentation of this file.
1 
35 // =========================================================================
36 #ifndef GUM_ARG_MAX_SET_H
37 #define GUM_ARG_MAX_SET_H
38 // =========================================================================
39 #include <cstdlib>
40 // =========================================================================
41 #include <agrum/core/sequence.h>
43 // =========================================================================
44 
45 namespace gum {
46 
55  template < typename GUM_SCALAR_VAL, typename GUM_SCALAR_SEQ >
57  class ArgMaxSet {
58  public:
59  // ###########################################################################
61  // ###########################################################################
63 
64  // ============================================================================
66  // ============================================================================
67  ArgMaxSet();
68 
69  // ============================================================================
71  // ============================================================================
72  ArgMaxSet(const GUM_SCALAR_VAL& val, const GUM_SCALAR_SEQ& elem);
73 
74  // ============================================================================
76  // ============================================================================
78 
81 
82  // ============================================================================
84  // ============================================================================
85  ~ArgMaxSet();
86 
87  // ============================================================================
89  // ============================================================================
90  void* operator new(size_t s) {
92  }
93  void operator delete(void* p) {
96  }
97 
99 
100  // ###########################################################################
102  // ###########################################################################
104 
105  // ============================================================================
107  // ============================================================================
109  return __argMaxSeq->beginSafe();
110  }
111 
112  // ============================================================================
114  // ============================================================================
116  return __argMaxSeq->endSafe();
117  }
118 
120 
121  // ###########################################################################
123  // ###########################################################################
125 
126  // ============================================================================
128  // ============================================================================
130  operator+=(const GUM_SCALAR_SEQ& elem);
131 
132  // ============================================================================
134  // ============================================================================
137 
138  // ============================================================================
140  // ============================================================================
141  const GUM_SCALAR_SEQ& operator[](const Idx i) const {
142  return __argMaxSeq->atPos(i);
143  }
144 
145  // ============================================================================
147  // ============================================================================
148  bool operator==(
149  const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ >& compared) const;
151  const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ >& compared) const {
152  return !(*this == compared);
153  }
154 
155  // ============================================================================
157  // ============================================================================
158  bool operator<(
159  const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ >& compared) const {
160  return __val < compared.value() ? true : false;
161  }
162  bool operator>(
163  const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ >& compared) const {
164  return compared < *this;
165  }
167  const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ >& compared) const {
168  return !(*this > compared);
169  }
171  const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ >& compared) const {
172  return !(*this < compared);
173  }
174 
176 
177  // ============================================================================
179  // ============================================================================
180  Idx size() const { return __argMaxSeq->size(); }
181 
182  // ============================================================================
184  // ============================================================================
185  const GUM_SCALAR_VAL& value() const { return __val; }
186 
187  bool exists(const GUM_SCALAR_SEQ& elem) const {
188  return __argMaxSeq->exists(elem);
189  }
190 
191  private:
194  GUM_SCALAR_VAL __val;
195 
196  public:
197  friend std::ostream& operator<<(std::ostream& streamy, const ArgMaxSet& objy) {
198  streamy << "Value : " << objy.value()
199  << " - Set : " << objy.__argMaxSeq->toString();
200  return streamy;
201  }
202  };
203 
204 } // End of namespace gum
205 
207 
208 #endif /* GUM_ARG_MAX_SET_H */
SequenceIteratorSafe< GUM_SCALAR_SEQ > endSafe() const
Iterator end.
Definition: argMaxSet.h:115
~ArgMaxSet()
Destructor.
Definition: argMaxSet_tpl.h:85
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
const iterator_safe & endSafe() const noexcept
Returns the safe end iterator.
Definition: sequence_tpl.h:634
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
bool operator==(const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ > &compared) const
Compares two ArgMaxSet to check if they are equals.
Size size() const noexcept
Returns the size of the sequence.
Definition: sequence_tpl.h:38
std::string toString() const
Displays the content of the sequence.
Definition: sequence_tpl.h:574
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Class to handle efficiently argMaxSet.
Definition: argMaxSet.h:57
iterator_safe beginSafe() const
Returns a safe begin iterator.
Definition: sequence_tpl.h:627
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:158
bool operator<=(const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ > &compared) const
Ajout d&#39;un élément.
Definition: argMaxSet.h:166
bool operator!=(const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ > &compared) const
Ajout d&#39;un élément.
Definition: argMaxSet.h:150
bool exists(const Key &k) const
Check the existence of k in the sequence.
Definition: sequence_tpl.h:402
bool operator>(const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ > &compared) const
Ajout d&#39;un élément.
Definition: argMaxSet.h:162
Sequence< GUM_SCALAR_SEQ > * __argMaxSeq
The very bone of the ArgMaxSet.
Definition: argMaxSet.h:193
friend std::ostream & operator<<(std::ostream &streamy, const ArgMaxSet &objy)
Definition: argMaxSet.h:197
SequenceIteratorSafe< GUM_SCALAR_SEQ > beginSafe() const
Iterator beginning.
Definition: argMaxSet.h:108
const GUM_SCALAR_VAL & value() const
Returns the value on which comparison are made.
Definition: argMaxSet.h:185
void deallocate(void *pDeallocatedObject, const size_t &objectSize)
Deallocates an object.
bool exists(const GUM_SCALAR_SEQ &elem) const
Definition: argMaxSet.h:187
ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ > & operator+=(const GUM_SCALAR_SEQ &elem)
Ajout d&#39;un élément.
GUM_SCALAR_VAL __val
Definition: argMaxSet.h:194
ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ > & operator=(const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ > &src)
Constructor.
Definition: argMaxSet_tpl.h:74
Size Idx
Type for indexes.
Definition: types.h:53
Idx size() const
Gives the size.
Definition: argMaxSet.h:180
void * allocate(const size_t &objectSize)
Allocates a block.
bool operator>=(const ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ > &compared) const
Ajout d&#39;un élément.
Definition: argMaxSet.h:170
static SmallObjectAllocator & instance()
ArgMaxSet()
Constructor.
Definition: argMaxSet_tpl.h:42
const GUM_SCALAR_SEQ & operator[](const Idx i) const
Gives the ith element.
Definition: argMaxSet.h:141
const Key & atPos(Idx i) const
Returns the object at the pos i.
Definition: sequence_tpl.h:500