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 >& operator=(
const IdCondSetIterator< ALLOC >& from);
104 IdCondSetIterator< ALLOC >& operator=(IdCondSetIterator< ALLOC >&& from);
110 NodeId operator*()
const;
113 bool operator!=(
const IdCondSetIterator< ALLOC >& from)
const;
116 bool operator==(
const IdCondSetIterator< ALLOC >& from)
const;
129 IdCondSetIterator< ALLOC >& operator++();
136 IdCondSetIterator< ALLOC >& operator+=(
const std::size_t i);
144 IdCondSetIterator< ALLOC > operator+(
const std::size_t i);
159 std::size_t pos()
const;
164 #ifndef DOXYGEN_SHOULD_SKIP_THIS 168 const Sequence< NodeId, ALLOC< NodeId > >* _seq_{
nullptr};
171 std::size_t _index_{std::size_t(0)};
177 friend class IdCondSet< ALLOC >;
196 template <
template <
typename >
class ALLOC = std::allocator >
197 class IdCondSet:
private ALLOC< NodeId > {
200 using allocator_type = ALLOC< NodeId >;
202 using iterator = IdCondSetIterator< ALLOC >;
203 using const_iterator = IdCondSetIterator< ALLOC >;
204 using iterator_safe = IdCondSetIterator< ALLOC >;
205 using const_iterator_safe = IdCondSetIterator< ALLOC >;
213 IdCondSet(
const allocator_type& alloc = allocator_type());
222 IdCondSet(
const std::vector< NodeId, ALLOC< NodeId > >& ids,
224 const bool ordered_ids,
225 const allocator_type& alloc = allocator_type());
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());
251 IdCondSet(NodeId var1,
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());
269 IdCondSet(NodeId var1,
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());
278 IdCondSet(
const IdCondSet< ALLOC >& from);
281 IdCondSet(
const IdCondSet< ALLOC >& from,
const allocator_type& alloc);
284 IdCondSet(IdCondSet< ALLOC >&& from);
287 IdCondSet(IdCondSet< ALLOC >&& from,
const allocator_type& alloc);
290 virtual IdCondSet< ALLOC >* clone()
const;
293 virtual IdCondSet< ALLOC >* clone(
const allocator_type& alloc)
const;
296 virtual ~IdCondSet();
307 IdCondSet< ALLOC >& operator=(
const IdCondSet< ALLOC >& from);
310 IdCondSet< ALLOC >& operator=(IdCondSet< ALLOC >&& from);
313 NodeId operator[](
const std::size_t index)
const;
316 bool operator==(
const IdCondSet< ALLOC >& from)
const;
319 bool operator!=(
const IdCondSet< ALLOC >& from)
const;
333 iterator_safe beginSafe()
const;
339 const iterator_safe& endSafe()
const;
345 iterator begin()
const;
351 const iterator& end()
const;
362 const Sequence< NodeId, ALLOC< NodeId > >& ids()
const;
365 IdCondSet< ALLOC > conditionalIdCondSet()
const;
368 std::size_t nbLHSIds()
const;
371 std::size_t nbRHSIds()
const;
374 bool contains(
const IdCondSet< ALLOC >& set)
const;
380 std::size_t size()
const;
384 std::size_t pos(
const NodeId id)
const;
387 bool exists(
const NodeId id)
const;
392 void erase(
const NodeId id);
395 bool hasConditioningSet()
const;
401 std::string toString()
const;
404 allocator_type getAllocator()
const;
409 #ifndef DOXYGEN_SHOULD_SKIP_THIS 413 Sequence< NodeId, ALLOC< NodeId > > _ids_;
416 std::size_t _nb_lhs_ids_{std::size_t(0)};
419 IdCondSetIterator< ALLOC > _end_safe_;
426 template <
template <
typename >
class ALLOC >
427 std::ostream& operator<<(std::ostream& stream,
const IdCondSet< ALLOC >& idset);
433 template <
template <
typename >
class ALLOC >
434 class HashFunc< learning::IdCondSet< ALLOC > >:
435 public HashFuncBase< learning::IdCondSet< ALLOC > > {
442 static Size castToSize(
const learning::IdCondSet< ALLOC >& key);
445 virtual Size operator()(
const learning::IdCondSet< ALLOC >& key)
const override final;
453 #include <agrum/tools/stattests/idCondSet_tpl.h>