aGrUM  0.17.2
a C++ library for (probabilistic) graphical models
idCondSet.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>
41 
42 namespace gum {
43 
44  namespace learning {
45 
46 
47  template < template < typename > class ALLOC >
48  class IdCondSet;
49 
50 
56  template < template < typename > class ALLOC = std::allocator >
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 
79 
81 
83 
86 
89 
91  virtual ~IdCondSetIterator();
92 
94 
95 
96  // ##########################################################################
98  // ##########################################################################
100 
103 
106 
111  NodeId operator*() const;
112 
114  bool operator!=(const IdCondSetIterator< ALLOC >& from) const;
115 
117  bool operator==(const IdCondSetIterator< ALLOC >& from) const;
118 
131 
137  IdCondSetIterator< ALLOC >& operator+=(const std::size_t i);
138 
144  IdCondSetIterator< 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 IdCondSet< ALLOC >;
178 
179 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
180  };
181 
182 
196  template < template < typename > class ALLOC = std::allocator >
197  class IdCondSet: private ALLOC< NodeId > {
198  public:
200  using allocator_type = ALLOC< NodeId >;
201 
206 
207  // ##########################################################################
209  // ##########################################################################
211 
213  IdCondSet(const allocator_type& alloc = allocator_type());
214 
216 
222  IdCondSet(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  IdCondSet(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  IdCondSet(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  IdCondSet(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  IdCondSet(const IdCondSet< ALLOC >& from);
279 
281  IdCondSet(const IdCondSet< ALLOC >& from, const allocator_type& alloc);
282 
285 
287  IdCondSet(IdCondSet< ALLOC >&& from, const allocator_type& alloc);
288 
290  virtual IdCondSet< ALLOC >* clone() const;
291 
293  virtual IdCondSet< ALLOC >* clone(const allocator_type& alloc) const;
294 
296  virtual ~IdCondSet();
297 
299 
300 
301  // ##########################################################################
303  // ##########################################################################
305 
308 
311 
313  NodeId operator[](const std::size_t index) const;
314 
316  bool operator==(const IdCondSet< ALLOC >& from) const;
317 
319  bool operator!=(const IdCondSet< 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  IdCondSet< ALLOC > conditionalIdCondSet() const;
366 
368  std::size_t nbLHSIds() const;
369 
371  std::size_t nbRHSIds() const;
372 
374  bool contains(const IdCondSet< 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  IdCondSetIterator< 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 IdCondSet< ALLOC >& idset);
428 
429  } /* namespace learning */
430 
431 
433  template < template < typename > class ALLOC >
434  class HashFunc< learning::IdCondSet< ALLOC > >:
435  public HashFuncBase< learning::IdCondSet< ALLOC > > {
436  public:
442  static Size castToSize(const learning::IdCondSet< ALLOC >& key);
443 
445  virtual Size
446  operator()(const learning::IdCondSet< 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 */
IdCondSetIterator< ALLOC > & operator+=(const std::size_t i)
Makes the iterator point to i elements further in the IdCondSet.
bool operator==(const IdCondSetIterator< ALLOC > &from) const
Checks whether two iterators point toward the same elements.
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
The generic class for storing (ordered) sequences of objects.
Definition: sequence.h:1022
bool operator!=(const IdCondSetIterator< ALLOC > &from) const
Checks whether two iterators point toward different elements.
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
Class template representing hashing function of LpCol.
Definition: hashFunc.h:471
std::size_t pos() const
Returns the position of the iterator in the IdCondSet.
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
Definition: agrum.h:25
NodeId & reference
types for STL compliance
Definition: idCondSet.h:63
IdCondSetIterator()
default constructor
IdCondSetIterator< ALLOC > operator+(const std::size_t i)
Returns a new iterator pointing to i further elements in the IdCondSet.
NodeId value_type
types for STL compliance
Definition: idCondSet.h:62
NodeId * pointer
types for STL compliance
Definition: idCondSet.h:65
std::ptrdiff_t difference_type
types for STL compliance
Definition: idCondSet.h:67
std::forward_iterator_tag iterator_category
types for STL compliance
Definition: idCondSet.h:61
NodeId operator*() const
Gives access to the content of the iterator.
const NodeId & const_reference
types for STL compliance
Definition: idCondSet.h:64
virtual ~IdCondSetIterator()
destructor
All hash functions should inherit from this class.
Definition: hashFunc.h:149
The iterators for IdSets.
Definition: idCondSet.h:57
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
const NodeId * const_pointer
types for STL compliance
Definition: idCondSet.h:66
IdCondSetIterator< ALLOC > & operator++()
Makes the iterator point to the next element in the IdCondSet.
Size NodeId
Type for node ids.
Definition: graphElements.h:98
ALLOC< NodeId > allocator_type
type for the allocators passed in arguments of methods
Definition: idCondSet.h:200
A class for storing a pair of sets of NodeIds, the second one corresponding to a conditional set...
Definition: idCondSet.h:48
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
IdCondSetIterator< ALLOC > & operator=(const IdCondSetIterator< ALLOC > &from)
copy operator