27 #ifndef GUM_LEARNING_ID_SET_H 28 #define GUM_LEARNING_ID_SET_H 33 #include <type_traits> 37 #include <agrum/agrum.h> 38 #include <agrum/tools/core/sequence.h> 39 #include <agrum/tools/graphs/graphElements.h> 46 template <
template <
typename >
class ALLOC >
55 template <
template <
typename >
class ALLOC = std::allocator >
56 class IdCondSetIterator {
60 using iterator_category = std::forward_iterator_tag;
61 using value_type = NodeId;
62 using reference = NodeId&;
63 using const_reference =
const NodeId&;
64 using pointer = NodeId*;
65 using const_pointer =
const NodeId*;
66 using difference_type = std::ptrdiff_t;
81 IdCondSetIterator(
const IdCondSet< ALLOC >& idset);
84 IdCondSetIterator(
const IdCondSetIterator< ALLOC >& from);
87 IdCondSetIterator(IdCondSetIterator< ALLOC >&& from);
90 virtual ~IdCondSetIterator();
101 IdCondSetIterator< ALLOC >&
102 operator=(
const IdCondSetIterator< ALLOC >& from);
105 IdCondSetIterator< ALLOC >& operator=(IdCondSetIterator< ALLOC >&& from);
111 NodeId operator*()
const;
114 bool operator!=(
const IdCondSetIterator< ALLOC >& from)
const;
117 bool operator==(
const IdCondSetIterator< ALLOC >& from)
const;
130 IdCondSetIterator< ALLOC >& operator++();
137 IdCondSetIterator< ALLOC >& operator+=(
const std::size_t i);
145 IdCondSetIterator< ALLOC > operator+(
const std::size_t i);
160 std::size_t pos()
const;
165 #ifndef DOXYGEN_SHOULD_SKIP_THIS 169 const Sequence< NodeId, ALLOC< NodeId > >* seq__{
nullptr};
172 std::size_t index__{std::size_t(0)};
178 friend class IdCondSet< ALLOC >;
197 template <
template <
typename >
class ALLOC = std::allocator >
198 class IdCondSet:
private ALLOC< NodeId > {
201 using allocator_type = ALLOC< NodeId >;
203 using iterator = IdCondSetIterator< ALLOC >;
204 using const_iterator = IdCondSetIterator< ALLOC >;
205 using iterator_safe = IdCondSetIterator< ALLOC >;
206 using const_iterator_safe = IdCondSetIterator< ALLOC >;
214 IdCondSet(
const allocator_type& alloc = allocator_type());
223 IdCondSet(
const std::vector< NodeId, ALLOC< NodeId > >& ids,
225 const bool ordered_ids,
226 const allocator_type& alloc = allocator_type());
235 IdCondSet(NodeId var1,
236 const std::vector< NodeId, ALLOC< NodeId > >& rhs_ids,
237 const bool ordered_rhs_ids =
false,
238 const allocator_type& alloc = allocator_type());
252 IdCondSet(NodeId var1,
254 const std::vector< NodeId, ALLOC< NodeId > >& rhs_ids,
255 const bool ordered_lhs_vars,
256 const bool ordered_rhs_ids =
false,
257 const allocator_type& alloc = allocator_type());
270 IdCondSet(NodeId var1,
273 const std::vector< NodeId, ALLOC< NodeId > >& rhs_ids,
274 const bool ordered_lhs_vars,
275 const bool ordered_rhs_ids =
false,
276 const allocator_type& alloc = allocator_type());
279 IdCondSet(
const IdCondSet< ALLOC >& from);
282 IdCondSet(
const IdCondSet< ALLOC >& from,
const allocator_type& alloc);
285 IdCondSet(IdCondSet< ALLOC >&& from);
288 IdCondSet(IdCondSet< ALLOC >&& from,
const allocator_type& alloc);
291 virtual IdCondSet< ALLOC >* clone()
const;
294 virtual IdCondSet< ALLOC >* clone(
const allocator_type& alloc)
const;
297 virtual ~IdCondSet();
308 IdCondSet< ALLOC >& operator=(
const IdCondSet< ALLOC >& from);
311 IdCondSet< ALLOC >& operator=(IdCondSet< ALLOC >&& from);
314 NodeId operator[](
const std::size_t index)
const;
317 bool operator==(
const IdCondSet< ALLOC >& from)
const;
320 bool operator!=(
const IdCondSet< ALLOC >& from)
const;
334 iterator_safe beginSafe()
const;
340 const iterator_safe& endSafe()
const;
346 iterator begin()
const;
352 const iterator& end()
const;
363 const Sequence< NodeId, ALLOC< NodeId > >& ids()
const;
366 IdCondSet< ALLOC > conditionalIdCondSet()
const;
369 std::size_t nbLHSIds()
const;
372 std::size_t nbRHSIds()
const;
375 bool contains(
const IdCondSet< ALLOC >& set)
const;
381 std::size_t size()
const;
385 std::size_t pos(
const NodeId id)
const;
388 bool exists(
const NodeId id)
const;
393 void erase(
const NodeId id);
396 bool hasConditioningSet()
const;
402 std::string toString()
const;
405 allocator_type getAllocator()
const;
410 #ifndef DOXYGEN_SHOULD_SKIP_THIS 414 Sequence< NodeId, ALLOC< NodeId > > ids__;
417 std::size_t nb_lhs_ids__{std::size_t(0)};
420 IdCondSetIterator< ALLOC > end_safe__;
427 template <
template <
typename >
class ALLOC >
428 std::ostream& operator<<(std::ostream& stream,
429 const IdCondSet< ALLOC >& idset);
435 template <
template <
typename >
class ALLOC >
436 class HashFunc< learning::IdCondSet< ALLOC > >:
437 public HashFuncBase< learning::IdCondSet< ALLOC > > {
444 static Size castToSize(
const learning::IdCondSet< ALLOC >& key);
448 operator()(
const learning::IdCondSet< ALLOC >& key)
const override final;
456 #include <agrum/tools/stattests/idCondSet_tpl.h>