26 #ifndef DOXYGEN_SHOULD_SKIP_THIS 35 template <
template <
typename >
class ALLOC >
37 GUM_CONSTRUCTOR(IdSetIterator);
42 template <
template <
typename >
class ALLOC >
44 __seq(&(idset.ids())) {
45 GUM_CONSTRUCTOR(IdSetIterator);
50 template <
template <
typename >
class ALLOC >
52 IdSetIterator< ALLOC >::IdSetIterator(
const IdSetIterator< ALLOC >& from) :
54 __index(from.__index) {
55 GUM_CONS_CPY(IdSetIterator);
60 template <
template <
typename >
class ALLOC >
61 INLINE IdSetIterator< ALLOC >::IdSetIterator(IdSetIterator< ALLOC >&& from) :
62 __seq(from.__seq), __index(from.__index) {
63 GUM_CONS_MOV(IdSetIterator);
68 template <
template <
typename >
class ALLOC >
69 INLINE IdSetIterator< ALLOC >::~IdSetIterator() {
70 GUM_DESTRUCTOR(IdSetIterator);
75 template <
template <
typename >
class ALLOC >
76 INLINE
void IdSetIterator< ALLOC >::__gotoEnd() {
78 __index = __seq->size();
80 __index = std::size_t(0);
85 template <
template <
typename >
class ALLOC >
86 INLINE IdSetIterator< ALLOC >& IdSetIterator< ALLOC >::
87 operator=(
const IdSetIterator< ALLOC >& from) {
89 __index = from.__index;
95 template <
template <
typename >
class ALLOC >
96 INLINE IdSetIterator< ALLOC >& IdSetIterator< ALLOC >::
97 operator=(IdSetIterator< ALLOC >&& from) {
99 __index = from.__index;
105 template <
template <
typename >
class ALLOC >
107 return __seq->operator[](__index);
112 template <
template <
typename >
class ALLOC >
114 operator!=(
const IdSetIterator< ALLOC >& from)
const {
115 return (__index != from.__index) || (__seq != from.__seq);
120 template <
template <
typename >
class ALLOC >
122 operator==(
const IdSetIterator< ALLOC >& from)
const {
128 template <
template <
typename >
class ALLOC >
129 INLINE IdSetIterator< ALLOC >& IdSetIterator< ALLOC >::operator++() {
136 template <
template <
typename >
class ALLOC >
137 INLINE IdSetIterator< ALLOC >& IdSetIterator< ALLOC >::
138 operator+=(
const std::size_t i) {
145 template <
template <
typename >
class ALLOC >
147 IdSetIterator< ALLOC > res(*
this);
154 template <
template <
typename >
class ALLOC >
155 std::size_t IdSetIterator< ALLOC >::pos()
const {
156 if (__seq ==
nullptr)
158 "The IdSet is empty, so its iterators have no position");
159 if (__index >= __seq->size())
161 "the IdSet iterator has no position because it reached " 172 template <
template <
typename >
class ALLOC >
173 INLINE
typename IdSet< ALLOC >::allocator_type
174 IdSet< ALLOC >::getAllocator()
const {
180 template <
template <
typename >
class ALLOC >
181 INLINE IdSet< ALLOC >::IdSet(
182 const typename IdSet< ALLOC >::allocator_type& alloc) :
185 GUM_CONSTRUCTOR(IdSet);
190 template <
template <
typename >
class ALLOC >
191 INLINE IdSet< ALLOC >::IdSet(
192 const std::vector<
NodeId, ALLOC< NodeId > >& ids,
194 const bool ordered_ids,
195 const typename IdSet< ALLOC >::allocator_type& alloc) :
198 __ids.resize(ids.size());
203 std::vector< NodeId, ALLOC< NodeId > > vect(ids);
204 std::sort(vect.begin(), vect.end());
205 for (
const auto id : vect)
208 for (
const auto id : ids)
212 if (!rhs_ids) __nb_lhs_ids = __ids.size();
215 __end_safe.__gotoEnd();
217 GUM_CONSTRUCTOR(IdSet);
222 template <
template <
typename >
class ALLOC >
223 INLINE IdSet< ALLOC >::IdSet(
225 const std::vector<
NodeId, ALLOC< NodeId > >& rhs_ids,
226 const bool ordered_rhs_ids,
227 const typename IdSet< ALLOC >::allocator_type& alloc) :
229 __nb_lhs_ids(
std::size_t(1)), __end_safe(*this) {
230 __ids.resize(rhs_ids.size() + std::size_t(1));
235 if (!ordered_rhs_ids) {
236 std::vector< NodeId, ALLOC< NodeId > > vect(rhs_ids);
237 std::sort(vect.begin(), vect.end());
238 for (
const auto id : vect)
241 for (
const auto id : rhs_ids)
246 __end_safe.__gotoEnd();
248 GUM_CONSTRUCTOR(IdSet);
253 template <
template <
typename >
class ALLOC >
254 INLINE IdSet< ALLOC >::IdSet(
257 const std::vector<
NodeId, ALLOC< NodeId > >& rhs_ids,
258 const bool ordered_lhs_vars,
259 const bool ordered_rhs_ids,
260 const typename IdSet< ALLOC >::allocator_type& alloc) :
262 __nb_lhs_ids(
std::size_t(2)), __end_safe(*this) {
263 __ids.resize(rhs_ids.size() + std::size_t(2));
267 if (!ordered_lhs_vars && (var1 > var2))
std::swap(var1, var2);
273 if (!ordered_rhs_ids) {
274 std::vector< NodeId, ALLOC< NodeId > > vect(rhs_ids);
275 std::sort(vect.begin(), vect.end());
276 for (
const auto id : vect)
279 for (
const auto id : rhs_ids)
284 __end_safe.__gotoEnd();
286 GUM_CONSTRUCTOR(IdSet);
291 template <
template <
typename >
class ALLOC >
292 INLINE IdSet< ALLOC >::IdSet(
296 const std::vector<
NodeId, ALLOC< NodeId > >& rhs_ids,
297 const bool ordered_lhs_vars,
298 const bool ordered_rhs_ids,
299 const typename IdSet< ALLOC >::allocator_type& alloc) :
301 __nb_lhs_ids(
std::size_t(3)), __end_safe(*this) {
302 __ids.resize(rhs_ids.size() + std::size_t(3));
306 if (!ordered_lhs_vars) {
317 if (!ordered_rhs_ids) {
318 std::vector< NodeId, ALLOC< NodeId > > vect(rhs_ids);
319 std::sort(vect.begin(), vect.end());
320 for (
const auto id : vect)
323 for (
const auto id : rhs_ids)
328 __end_safe.__gotoEnd();
330 GUM_CONSTRUCTOR(IdSet);
335 template <
template <
typename >
class ALLOC >
336 INLINE IdSet< ALLOC >::IdSet(
337 const IdSet< ALLOC >& from,
338 const typename IdSet< ALLOC >::allocator_type& alloc) :
340 __ids(from.__ids), __nb_lhs_ids(from.__nb_lhs_ids), __end_safe(*this) {
341 __end_safe.__gotoEnd();
347 template <
template <
typename >
class ALLOC >
348 INLINE IdSet< ALLOC >::IdSet(
const IdSet< ALLOC >& from) :
349 IdSet< ALLOC >(from, from.getAllocator()) {}
353 template <
template <
typename >
class ALLOC >
354 INLINE IdSet< ALLOC >::IdSet(
355 IdSet< ALLOC >&& from,
356 const typename IdSet< ALLOC >::allocator_type& alloc) :
358 __ids(
std::move(from.__ids)), __nb_lhs_ids(from.__nb_lhs_ids),
360 __end_safe.__gotoEnd();
366 template <
template <
typename >
class ALLOC >
367 INLINE IdSet< ALLOC >::IdSet(IdSet< ALLOC >&& from) :
368 IdSet< ALLOC >(
std::move(from), from.getAllocator()) {}
372 template <
template <
typename >
class ALLOC >
373 IdSet< ALLOC >* IdSet< ALLOC >::clone(
374 const typename IdSet< ALLOC >::allocator_type& alloc)
const {
375 ALLOC< IdSet< ALLOC > > allocator(alloc);
376 IdSet< ALLOC >* new_set = allocator.allocate(1);
378 allocator.construct(new_set, *
this, alloc);
380 allocator.deallocate(new_set, 1);
389 template <
template <
typename >
class ALLOC >
390 IdSet< ALLOC >* IdSet< ALLOC >::clone()
const {
391 return clone(this->getAllocator());
396 template <
template <
typename >
class ALLOC >
397 INLINE IdSet< ALLOC >::~IdSet() {
398 GUM_DESTRUCTOR(IdSet);
403 template <
template <
typename >
class ALLOC >
404 INLINE IdSet< ALLOC >& IdSet< ALLOC >::operator=(
const IdSet< ALLOC >& from) {
407 __nb_lhs_ids = from.__nb_lhs_ids;
408 __end_safe.__gotoEnd();
415 template <
template <
typename >
class ALLOC >
416 INLINE IdSet< ALLOC >& IdSet< ALLOC >::operator=(IdSet< ALLOC >&& from) {
418 __ids = std::move(from.__ids);
419 __nb_lhs_ids = from.__nb_lhs_ids;
420 __end_safe.__gotoEnd();
427 template <
template <
typename >
class ALLOC >
428 INLINE
NodeId IdSet< ALLOC >::operator[](
const std::size_t index)
const {
429 return __ids.atPos(index);
434 template <
template <
typename >
class ALLOC >
436 if (__nb_lhs_ids != from.__nb_lhs_ids)
return false;
438 const std::size_t size = __ids.size();
440 if (size != from.__ids.size())
return false;
442 for (std::size_t i = std::size_t(0); i < size; ++i) {
443 if (__ids[i] != from.__ids[i])
return false;
451 template <
template <
typename >
class ALLOC >
458 template <
template <
typename >
class ALLOC >
459 INLINE
typename IdSet< ALLOC >::iterator_safe
460 IdSet< ALLOC >::beginSafe()
const {
461 return IdSetIterator< ALLOC >(*this);
466 template <
template <
typename >
class ALLOC >
467 INLINE
const typename IdSet< ALLOC >::iterator_safe&
468 IdSet< ALLOC >::endSafe()
const {
474 template <
template <
typename >
class ALLOC >
475 INLINE
typename IdSet< ALLOC >::iterator IdSet< ALLOC >::begin()
const {
476 return IdSetIterator< ALLOC >(*this);
481 template <
template <
typename >
class ALLOC >
482 INLINE
const typename IdSet< ALLOC >::iterator& IdSet< ALLOC >::end()
const {
488 template <
template <
typename >
class ALLOC >
489 INLINE
const Sequence< NodeId, ALLOC< NodeId > >& IdSet< ALLOC >::ids()
const {
495 template <
template <
typename >
class ALLOC >
496 IdSet< ALLOC > IdSet< ALLOC >::conditionalIdSet()
const {
497 IdSet< ALLOC >
set(this->getAllocator());
498 const std::size_t size = __ids.size();
499 for (std::size_t i = __nb_lhs_ids; i < size; ++i)
500 set.__ids << __ids[i];
501 set.__end_safe.__gotoEnd();
507 template <
template <
typename >
class ALLOC >
508 void IdSet< ALLOC >::erase(
const NodeId id) {
510 const std::size_t size = __ids.size();
511 std::size_t pos = std::size_t(0);
512 for (; pos < size; ++pos) {
513 if (__ids[pos] ==
id)
break;
519 if (pos < __nb_lhs_ids) --__nb_lhs_ids;
520 __end_safe.__gotoEnd();
526 template <
template <
typename >
class ALLOC >
527 std::string IdSet< ALLOC >::toString()
const {
528 std::stringstream str;
533 for (std::size_t i = std::size_t(0); i < __nb_lhs_ids; ++i) {
542 for (
auto iter = __ids.begin() + __nb_lhs_ids; iter != __ids.end(); ++iter) {
559 template <
template <
typename >
class ALLOC >
560 INLINE std::size_t IdSet< ALLOC >::nbLHSIds()
const {
566 template <
template <
typename >
class ALLOC >
567 INLINE std::size_t IdSet< ALLOC >::nbRHSIds()
const {
568 return __ids.size() - __nb_lhs_ids;
573 template <
template <
typename >
class ALLOC >
574 bool IdSet< ALLOC >::contains(
const IdSet< ALLOC >&
set)
const {
575 if (
set.__ids.size() > __ids.size())
return false;
576 for (
const auto node :
set.__ids) {
577 if (!__ids.exists(node))
return false;
584 template <
template <
typename >
class ALLOC >
585 INLINE
void IdSet< ALLOC >::clear() {
587 __nb_lhs_ids = std::size_t(0);
588 __end_safe.__gotoEnd();
593 template <
template <
typename >
class ALLOC >
594 INLINE std::size_t IdSet< ALLOC >::size()
const {
600 template <
template <
typename >
class ALLOC >
601 INLINE std::size_t IdSet< ALLOC >::pos(
const NodeId id)
const {
602 return __ids.pos(
id);
607 template <
template <
typename >
class ALLOC >
608 INLINE
bool IdSet< ALLOC >::exists(
const NodeId id)
const {
609 return __ids.exists(
id);
614 template <
template <
typename >
class ALLOC >
615 INLINE
bool IdSet< ALLOC >::hasConditioningSet()
const {
616 return __nb_lhs_ids != __ids.size();
621 template <
template <
typename >
class ALLOC >
622 INLINE
bool IdSet< ALLOC >::empty()
const {
623 return __ids.empty();
628 template <
template <
typename >
class ALLOC >
629 std::ostream& operator<<(std::ostream& stream, const IdSet< ALLOC >& idset) {
630 return stream << idset.toString();
637 template <
template <
typename >
class ALLOC >
638 Size HashFunc< learning::IdSet< ALLOC > >::castToSize(
639 const learning::IdSet< ALLOC >& key) {
641 const Sequence< NodeId, ALLOC< NodeId > >& vect = key.ids();
642 const std::size_t size = vect.size();
644 std::size_t i = std::size_t(0);
656 template <
template <
typename >
class ALLOC >
657 INLINE
Size HashFunc< learning::IdSet< ALLOC > >::
658 operator()(
const learning::IdSet< 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.
gum is the global namespace for all aGrUM entities
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)
IdSetIterator()
default constructor
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)