29 #ifndef DOXYGEN_SHOULD_SKIP_THIS 38 template <
template <
typename >
class ALLOC >
40 GUM_CONSTRUCTOR(IdCondSetIterator);
45 template <
template <
typename >
class ALLOC >
47 const IdCondSet< ALLOC >& idset) :
48 __seq(&(idset.ids())) {
49 GUM_CONSTRUCTOR(IdCondSetIterator);
54 template <
template <
typename >
class ALLOC >
55 INLINE IdCondSetIterator< ALLOC >::IdCondSetIterator(
56 const IdCondSetIterator< ALLOC >& from) :
58 __index(from.__index) {
59 GUM_CONS_CPY(IdCondSetIterator);
64 template <
template <
typename >
class ALLOC >
65 INLINE IdCondSetIterator< ALLOC >::IdCondSetIterator(
66 IdCondSetIterator< ALLOC >&& from) :
68 __index(from.__index) {
69 GUM_CONS_MOV(IdCondSetIterator);
74 template <
template <
typename >
class ALLOC >
75 INLINE IdCondSetIterator< ALLOC >::~IdCondSetIterator() {
76 GUM_DESTRUCTOR(IdCondSetIterator);
81 template <
template <
typename >
class ALLOC >
82 INLINE
void IdCondSetIterator< ALLOC >::__gotoEnd() {
84 __index = __seq->size();
86 __index = std::size_t(0);
91 template <
template <
typename >
class ALLOC >
92 INLINE IdCondSetIterator< ALLOC >& IdCondSetIterator< ALLOC >::operator=(
93 const IdCondSetIterator< ALLOC >& from) {
95 __index = from.__index;
101 template <
template <
typename >
class ALLOC >
102 INLINE IdCondSetIterator< ALLOC >&
103 IdCondSetIterator< ALLOC >::operator=(IdCondSetIterator< ALLOC >&& from) {
105 __index = from.__index;
111 template <
template <
typename >
class ALLOC >
113 return __seq->operator[](__index);
118 template <
template <
typename >
class ALLOC >
120 const IdCondSetIterator< ALLOC >& from)
const {
121 return (__index != from.__index) || (__seq != from.__seq);
126 template <
template <
typename >
class ALLOC >
128 const IdCondSetIterator< ALLOC >& from)
const {
134 template <
template <
typename >
class ALLOC >
135 INLINE IdCondSetIterator< ALLOC >& IdCondSetIterator< ALLOC >::operator++() {
142 template <
template <
typename >
class ALLOC >
143 INLINE IdCondSetIterator< ALLOC >&
144 IdCondSetIterator< ALLOC >::operator+=(
const std::size_t i) {
151 template <
template <
typename >
class ALLOC >
152 IdCondSetIterator< ALLOC >
154 IdCondSetIterator< ALLOC > res(*
this);
161 template <
template <
typename >
class ALLOC >
162 std::size_t IdCondSetIterator< ALLOC >::pos()
const {
163 if (__seq ==
nullptr)
165 "The IdCondSet is empty, so its iterators have no position");
166 if (__index >= __seq->size())
168 "the IdCondSet iterator has no position because it reached " 179 template <
template <
typename >
class ALLOC >
180 INLINE
typename IdCondSet< ALLOC >::allocator_type
181 IdCondSet< ALLOC >::getAllocator()
const {
187 template <
template <
typename >
class ALLOC >
188 INLINE IdCondSet< ALLOC >::IdCondSet(
189 const typename IdCondSet< ALLOC >::allocator_type& alloc) :
192 GUM_CONSTRUCTOR(IdCondSet);
197 template <
template <
typename >
class ALLOC >
198 INLINE IdCondSet< ALLOC >::IdCondSet(
199 const std::vector<
NodeId, ALLOC< NodeId > >& ids,
201 const bool ordered_ids,
202 const typename IdCondSet< ALLOC >::allocator_type& alloc) :
205 __ids.resize(ids.size());
210 std::vector< NodeId, ALLOC< NodeId > > vect(ids);
211 std::sort(vect.begin(), vect.end());
212 for (
const auto id: vect)
215 for (
const auto id: ids)
219 if (!rhs_ids) __nb_lhs_ids = __ids.size();
222 __end_safe.__gotoEnd();
224 GUM_CONSTRUCTOR(IdCondSet);
229 template <
template <
typename >
class ALLOC >
230 INLINE IdCondSet< ALLOC >::IdCondSet(
232 const std::vector<
NodeId, ALLOC< NodeId > >& rhs_ids,
233 const bool ordered_rhs_ids,
234 const typename IdCondSet< ALLOC >::allocator_type& alloc) :
236 __nb_lhs_ids(
std::size_t(1)), __end_safe(*this) {
237 __ids.resize(rhs_ids.size() + std::size_t(1));
242 if (!ordered_rhs_ids) {
243 std::vector< NodeId, ALLOC< NodeId > > vect(rhs_ids);
244 std::sort(vect.begin(), vect.end());
245 for (
const auto id: vect)
248 for (
const auto id: rhs_ids)
253 __end_safe.__gotoEnd();
255 GUM_CONSTRUCTOR(IdCondSet);
260 template <
template <
typename >
class ALLOC >
261 INLINE IdCondSet< ALLOC >::IdCondSet(
264 const std::vector<
NodeId, ALLOC< NodeId > >& rhs_ids,
265 const bool ordered_lhs_vars,
266 const bool ordered_rhs_ids,
267 const typename IdCondSet< ALLOC >::allocator_type& alloc) :
269 __nb_lhs_ids(
std::size_t(2)), __end_safe(*this) {
270 __ids.resize(rhs_ids.size() + std::size_t(2));
274 if (!ordered_lhs_vars && (var1 > var2))
std::swap(var1, var2);
280 if (!ordered_rhs_ids) {
281 std::vector< NodeId, ALLOC< NodeId > > vect(rhs_ids);
282 std::sort(vect.begin(), vect.end());
283 for (
const auto id: vect)
286 for (
const auto id: rhs_ids)
291 __end_safe.__gotoEnd();
293 GUM_CONSTRUCTOR(IdCondSet);
298 template <
template <
typename >
class ALLOC >
299 INLINE IdCondSet< ALLOC >::IdCondSet(
303 const std::vector<
NodeId, ALLOC< NodeId > >& rhs_ids,
304 const bool ordered_lhs_vars,
305 const bool ordered_rhs_ids,
306 const typename IdCondSet< ALLOC >::allocator_type& alloc) :
308 __nb_lhs_ids(
std::size_t(3)), __end_safe(*this) {
309 __ids.resize(rhs_ids.size() + std::size_t(3));
313 if (!ordered_lhs_vars) {
324 if (!ordered_rhs_ids) {
325 std::vector< NodeId, ALLOC< NodeId > > vect(rhs_ids);
326 std::sort(vect.begin(), vect.end());
327 for (
const auto id: vect)
330 for (
const auto id: rhs_ids)
335 __end_safe.__gotoEnd();
337 GUM_CONSTRUCTOR(IdCondSet);
342 template <
template <
typename >
class ALLOC >
343 INLINE IdCondSet< ALLOC >::IdCondSet(
344 const IdCondSet< ALLOC >& from,
345 const typename IdCondSet< ALLOC >::allocator_type& alloc) :
347 __ids(from.__ids), __nb_lhs_ids(from.__nb_lhs_ids), __end_safe(*this) {
348 __end_safe.__gotoEnd();
349 GUM_CONS_CPY(IdCondSet);
354 template <
template <
typename >
class ALLOC >
355 INLINE IdCondSet< ALLOC >::IdCondSet(
const IdCondSet< ALLOC >& from) :
356 IdCondSet< ALLOC >(from, from.getAllocator()) {}
360 template <
template <
typename >
class ALLOC >
361 INLINE IdCondSet< ALLOC >::IdCondSet(
362 IdCondSet< ALLOC >&& from,
363 const typename IdCondSet< ALLOC >::allocator_type& alloc) :
365 __ids(
std::move(from.__ids)), __nb_lhs_ids(from.__nb_lhs_ids),
367 __end_safe.__gotoEnd();
368 GUM_CONS_MOV(IdCondSet);
373 template <
template <
typename >
class ALLOC >
374 INLINE IdCondSet< ALLOC >::IdCondSet(IdCondSet< ALLOC >&& from) :
375 IdCondSet< ALLOC >(
std::move(from), from.getAllocator()) {}
379 template <
template <
typename >
class ALLOC >
380 IdCondSet< ALLOC >* IdCondSet< ALLOC >::clone(
381 const typename IdCondSet< ALLOC >::allocator_type& alloc)
const {
382 ALLOC< IdCondSet< ALLOC > > allocator(alloc);
383 IdCondSet< ALLOC >* new_set = allocator.allocate(1);
385 allocator.construct(new_set, *
this, alloc);
387 allocator.deallocate(new_set, 1);
396 template <
template <
typename >
class ALLOC >
397 IdCondSet< ALLOC >* IdCondSet< ALLOC >::clone()
const {
398 return clone(this->getAllocator());
403 template <
template <
typename >
class ALLOC >
404 INLINE IdCondSet< ALLOC >::~IdCondSet() {
405 GUM_DESTRUCTOR(IdCondSet);
410 template <
template <
typename >
class ALLOC >
411 INLINE IdCondSet< ALLOC >&
412 IdCondSet< ALLOC >::operator=(
const IdCondSet< ALLOC >& from) {
415 __nb_lhs_ids = from.__nb_lhs_ids;
416 __end_safe.__gotoEnd();
423 template <
template <
typename >
class ALLOC >
424 INLINE IdCondSet< ALLOC >&
425 IdCondSet< ALLOC >::operator=(IdCondSet< ALLOC >&& from) {
427 __ids = std::move(from.__ids);
428 __nb_lhs_ids = from.__nb_lhs_ids;
429 __end_safe.__gotoEnd();
436 template <
template <
typename >
class ALLOC >
437 INLINE
NodeId IdCondSet< ALLOC >::operator[](
const std::size_t index)
const {
438 return __ids.atPos(index);
443 template <
template <
typename >
class ALLOC >
446 if (__nb_lhs_ids != from.__nb_lhs_ids)
return false;
448 const std::size_t size = __ids.size();
450 if (size != from.__ids.size())
return false;
452 for (std::size_t i = std::size_t(0); i < size; ++i) {
453 if (__ids[i] != from.__ids[i])
return false;
461 template <
template <
typename >
class ALLOC >
469 template <
template <
typename >
class ALLOC >
470 INLINE
typename IdCondSet< ALLOC >::iterator_safe
471 IdCondSet< ALLOC >::beginSafe()
const {
472 return IdCondSetIterator< ALLOC >(*this);
477 template <
template <
typename >
class ALLOC >
478 INLINE
const typename IdCondSet< ALLOC >::iterator_safe&
479 IdCondSet< ALLOC >::endSafe()
const {
485 template <
template <
typename >
class ALLOC >
486 INLINE
typename IdCondSet< ALLOC >::iterator
487 IdCondSet< ALLOC >::begin()
const {
488 return IdCondSetIterator< ALLOC >(*this);
493 template <
template <
typename >
class ALLOC >
494 INLINE
const typename IdCondSet< ALLOC >::iterator&
495 IdCondSet< ALLOC >::end()
const {
501 template <
template <
typename >
class ALLOC >
502 INLINE
const Sequence< NodeId, ALLOC< NodeId > >&
503 IdCondSet< ALLOC >::ids()
const {
509 template <
template <
typename >
class ALLOC >
510 IdCondSet< ALLOC > IdCondSet< ALLOC >::conditionalIdCondSet()
const {
511 IdCondSet< ALLOC >
set(this->getAllocator());
512 const std::size_t size = __ids.size();
513 for (std::size_t i = __nb_lhs_ids; i < size; ++i)
514 set.__ids << __ids[i];
515 set.__end_safe.__gotoEnd();
521 template <
template <
typename >
class ALLOC >
522 void IdCondSet< ALLOC >::erase(
const NodeId id) {
524 const std::size_t size = __ids.size();
525 std::size_t pos = std::size_t(0);
526 for (; pos < size; ++pos) {
527 if (__ids[pos] ==
id)
break;
533 if (pos < __nb_lhs_ids) --__nb_lhs_ids;
534 __end_safe.__gotoEnd();
540 template <
template <
typename >
class ALLOC >
541 std::string IdCondSet< ALLOC >::toString()
const {
542 std::stringstream str;
547 for (std::size_t i = std::size_t(0); i < __nb_lhs_ids; ++i) {
556 for (
auto iter = __ids.begin() + __nb_lhs_ids; iter != __ids.end(); ++iter) {
573 template <
template <
typename >
class ALLOC >
574 INLINE std::size_t IdCondSet< ALLOC >::nbLHSIds()
const {
580 template <
template <
typename >
class ALLOC >
581 INLINE std::size_t IdCondSet< ALLOC >::nbRHSIds()
const {
582 return __ids.size() - __nb_lhs_ids;
587 template <
template <
typename >
class ALLOC >
588 bool IdCondSet< ALLOC >::contains(
const IdCondSet< ALLOC >&
set)
const {
589 if (
set.__ids.size() > __ids.size())
return false;
590 for (
const auto node:
set.__ids) {
591 if (!__ids.exists(node))
return false;
598 template <
template <
typename >
class ALLOC >
599 INLINE
void IdCondSet< ALLOC >::clear() {
601 __nb_lhs_ids = std::size_t(0);
602 __end_safe.__gotoEnd();
607 template <
template <
typename >
class ALLOC >
608 INLINE std::size_t IdCondSet< ALLOC >::size()
const {
614 template <
template <
typename >
class ALLOC >
615 INLINE std::size_t IdCondSet< ALLOC >::pos(
const NodeId id)
const {
616 return __ids.pos(
id);
621 template <
template <
typename >
class ALLOC >
622 INLINE
bool IdCondSet< ALLOC >::exists(
const NodeId id)
const {
623 return __ids.exists(
id);
628 template <
template <
typename >
class ALLOC >
629 INLINE
bool IdCondSet< ALLOC >::hasConditioningSet()
const {
630 return __nb_lhs_ids != __ids.size();
635 template <
template <
typename >
class ALLOC >
636 INLINE
bool IdCondSet< ALLOC >::empty()
const {
637 return __ids.empty();
642 template <
template <
typename >
class ALLOC >
643 std::ostream&
operator<<(std::ostream& stream,
644 const IdCondSet< ALLOC >& idset) {
645 return stream << idset.toString();
652 template <
template <
typename >
class ALLOC >
653 Size HashFunc< learning::IdCondSet< ALLOC > >::castToSize(
654 const learning::IdCondSet< ALLOC >& key) {
656 const Sequence< NodeId, ALLOC< NodeId > >& vect = key.ids();
657 const std::size_t size = vect.size();
659 std::size_t i = std::size_t(0);
671 template <
template <
typename >
class ALLOC >
672 INLINE
Size HashFunc< learning::IdCondSet< ALLOC > >::operator()(
673 const learning::IdCondSet< ALLOC >& key)
const {
static constexpr Size gold
void swap(HashTable< LpCol, double > *&a, HashTable< LpCol, double > *&b)
Swap the addresses of two pointers to hashTables.
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
IdCondSetIterator()
default constructor
std::ostream & operator<<(std::ostream &output, const BayesNet< GUM_SCALAR > &bn)
Prints map's DAG in output using the Graphviz-dot format.
LpExpr operator+(LpExpr &&lhs, const T2 &rhs)
Overload of operator + between anything ( a scalar, a variable or an expression ) and anything except...
bool operator==(const TiXmlString &a, const TiXmlString &b)
LpExpr operator*(const SCALAR &lhs, const LpCol &rhs)
Overload of operator * between a scalar and a variable.
bool operator!=(const TiXmlString &a, const TiXmlString &b)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size NodeId
Type for node ids.
#define GUM_ERROR(type, msg)