aGrUM  0.16.0
idSet.h
Go to the documentation of this file.
1 
28 #ifndef GUM_LEARNING_ID_SET_H
29 #define GUM_LEARNING_ID_SET_H
30 
31 #include <iostream>
32 #include <sstream>
33 #include <string>
34 #include <type_traits>
35 #include <utility>
36 #include <vector>
37 
38 #include <agrum/agrum.h>
39 #include <agrum/core/sequence.h>
41 
42 namespace gum {
43 
44  namespace learning {
45 
46 
47  template < template < typename > class ALLOC >
48  class IdSet;
49 
50 
56  template < template < typename > class ALLOC = std::allocator >
57  class IdSetIterator {
58  public:
61  using iterator_category = std::forward_iterator_tag;
62  using value_type = NodeId;
63  using reference = NodeId&;
64  using const_reference = const NodeId&;
65  using pointer = NodeId*;
66  using const_pointer = const NodeId*;
67  using difference_type = std::ptrdiff_t;
69 
70 
71  // ##########################################################################
73  // ##########################################################################
75 
77 
78  IdSetIterator();
79 
81 
82  IdSetIterator(const IdSet< ALLOC >& idset);
83 
86 
89 
91  virtual ~IdSetIterator();
92 
94 
95 
96  // ##########################################################################
98  // ##########################################################################
100 
103 
106 
111  NodeId operator*() const;
112 
114  bool operator!=(const IdSetIterator< ALLOC >& from) const;
115 
117  bool operator==(const IdSetIterator< ALLOC >& from) const;
118 
131 
137  IdSetIterator< ALLOC >& operator+=(const std::size_t i);
138 
144  IdSetIterator< ALLOC > operator+(const std::size_t i);
145 
147 
148 
149  // ##########################################################################
151  // ##########################################################################
153 
159  std::size_t pos() const;
160 
162 
163 
164 #ifndef DOXYGEN_SHOULD_SKIP_THIS
165 
166  private:
168  const Sequence< NodeId, ALLOC< NodeId > >* __seq{nullptr};
169 
171  std::size_t __index{std::size_t(0)};
172 
173 
175  void __gotoEnd();
176 
177  friend class IdSet< ALLOC >;
178 
179 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
180  };
181 
182 
196  template < template < typename > class ALLOC = std::allocator >
197  class IdSet : private ALLOC< NodeId > {
198  public:
200  using allocator_type = ALLOC< NodeId >;
201 
206 
207  // ##########################################################################
209  // ##########################################################################
211 
213  IdSet(const allocator_type& alloc = allocator_type());
214 
216 
222  IdSet(const std::vector< NodeId, ALLOC< NodeId > >& ids,
223  const bool rhs_ids,
224  const bool ordered_ids,
225  const allocator_type& alloc = allocator_type());
226 
228 
234  IdSet(NodeId var1,
235  const std::vector< NodeId, ALLOC< NodeId > >& rhs_ids,
236  const bool ordered_rhs_ids = false,
237  const allocator_type& alloc = allocator_type());
238 
240 
251  IdSet(NodeId var1,
252  NodeId var2,
253  const std::vector< NodeId, ALLOC< NodeId > >& rhs_ids,
254  const bool ordered_lhs_vars,
255  const bool ordered_rhs_ids = false,
256  const allocator_type& alloc = allocator_type());
257 
259 
269  IdSet(NodeId var1,
270  NodeId var2,
271  NodeId var3,
272  const std::vector< NodeId, ALLOC< NodeId > >& rhs_ids,
273  const bool ordered_lhs_vars,
274  const bool ordered_rhs_ids = false,
275  const allocator_type& alloc = allocator_type());
276 
278  IdSet(const IdSet< ALLOC >& from);
279 
281  IdSet(const IdSet< ALLOC >& from, const allocator_type& alloc);
282 
284  IdSet(IdSet< ALLOC >&& from);
285 
287  IdSet(IdSet< ALLOC >&& from, const allocator_type& alloc);
288 
290  virtual IdSet< ALLOC >* clone() const;
291 
293  virtual IdSet< ALLOC >* clone(const allocator_type& alloc) const;
294 
296  virtual ~IdSet();
297 
299 
300 
301  // ##########################################################################
303  // ##########################################################################
305 
308 
311 
313  NodeId operator[](const std::size_t index) const;
314 
316  bool operator==(const IdSet< ALLOC >& from) const;
317 
319  bool operator!=(const IdSet< ALLOC >& from) const;
320 
322 
323 
324  // ##########################################################################
326  // ##########################################################################
328 
333  iterator_safe beginSafe() const;
334 
339  const iterator_safe& endSafe() const;
340 
345  iterator begin() const;
346 
351  const iterator& end() const;
352 
354 
355 
356  // ##########################################################################
358  // ##########################################################################
360 
362  const Sequence< NodeId, ALLOC< NodeId > >& ids() const;
363 
365  IdSet< ALLOC > conditionalIdSet() const;
366 
368  std::size_t nbLHSIds() const;
369 
371  std::size_t nbRHSIds() const;
372 
374  bool contains(const IdSet< ALLOC >& set) const;
375 
377  void clear();
378 
380  std::size_t size() const;
381 
383 
384  std::size_t pos(const NodeId id) const;
385 
387  bool exists(const NodeId id) const;
388 
390 
392  void erase(const NodeId id);
393 
395  bool hasConditioningSet() const;
396 
398  bool empty() const;
399 
401  std::string toString() const;
402 
404  allocator_type getAllocator() const;
405 
407 
408 
409 #ifndef DOXYGEN_SHOULD_SKIP_THIS
410 
411  private:
414 
416  std::size_t __nb_lhs_ids{std::size_t(0)};
417 
419  IdSetIterator< ALLOC > __end_safe;
420 
421 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
422  };
423 
424 
426  template < template < typename > class ALLOC >
427  std::ostream& operator<<(std::ostream& stream, const IdSet< ALLOC >& idset);
428 
429  } /* namespace learning */
430 
431 
433  template < template < typename > class ALLOC >
434  class HashFunc< learning::IdSet< ALLOC > >
435  : public HashFuncBase< learning::IdSet< ALLOC > > {
436  public:
442  static Size castToSize(const learning::IdSet< ALLOC >& key);
443 
445  virtual Size
446  operator()(const learning::IdSet< ALLOC >& key) const override final;
447  };
448 
449 
450 } /* namespace gum */
451 
452 
453 // always include the template implementation
455 
456 #endif /* GUM_LEARNING_ID_SET_H */
const NodeId * const_pointer
types for STL compliance
Definition: idSet.h:66
IdSetIterator< ALLOC > operator+(const std::size_t i)
Returns a new iterator pointing to i further elements in the IdSet.
bool operator!=(const IdSetIterator< ALLOC > &from) const
Checks whether two iterators point toward different elements.
IdSetIterator< ALLOC > & operator=(const IdSetIterator< ALLOC > &from)
copy operator
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
The iterators for IdSets.
Definition: idSet.h:57
bool operator==(const IdSetIterator< ALLOC > &from) const
Checks whether two iterators point toward the same elements.
virtual ~IdSetIterator()
destructor
The generic class for storing (ordered) sequences of objects.
Definition: sequence.h:1022
ALLOC< NodeId > allocator_type
type for the allocators passed in arguments of methods
Definition: idSet.h:200
A class for storing a pair of sets of NodeIds, the second one corresponding to a conditional set...
Definition: idSet.h:48
Class template representing hashing function of LpCol.
Definition: hashFunc.h:471
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
NodeId & reference
types for STL compliance
Definition: idSet.h:63
IdSetIterator< ALLOC > & operator+=(const std::size_t i)
Makes the iterator point to i elements further in the IdSet.
NodeId * pointer
types for STL compliance
Definition: idSet.h:65
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
IdSetIterator()
default constructor
NodeId operator*() const
Gives access to the content of the iterator.
const NodeId & const_reference
types for STL compliance
Definition: idSet.h:64
NodeId value_type
types for STL compliance
Definition: idSet.h:62
All hash functions should inherit from this class.
Definition: hashFunc.h:149
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
IdSetIterator< ALLOC > & operator++()
Makes the iterator point to the next element in the IdSet.
std::forward_iterator_tag iterator_category
types for STL compliance
Definition: idSet.h:61
std::size_t pos() const
Returns the position of the iterator in the IdSet.
Size NodeId
Type for node ids.
Definition: graphElements.h:98
std::ptrdiff_t difference_type
types for STL compliance
Definition: idSet.h:67
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.