29 #ifndef DOXYGEN_SHOULD_SKIP_THIS 38 template <
template <
typename >
class ALLOC >
40 GUM_CONSTRUCTOR(IdSetIterator);
45 template <
template <
typename >
class ALLOC >
47 __seq(&(idset.ids())) {
48 GUM_CONSTRUCTOR(IdSetIterator);
53 template <
template <
typename >
class ALLOC >
55 IdSetIterator< ALLOC >::IdSetIterator(
const IdSetIterator< ALLOC >& from) :
57 __index(from.__index) {
58 GUM_CONS_CPY(IdSetIterator);
63 template <
template <
typename >
class ALLOC >
64 INLINE IdSetIterator< ALLOC >::IdSetIterator(IdSetIterator< ALLOC >&& from) :
65 __seq(from.__seq), __index(from.__index) {
66 GUM_CONS_MOV(IdSetIterator);
71 template <
template <
typename >
class ALLOC >
72 INLINE IdSetIterator< ALLOC >::~IdSetIterator() {
73 GUM_DESTRUCTOR(IdSetIterator);
78 template <
template <
typename >
class ALLOC >
79 INLINE
void IdSetIterator< ALLOC >::__gotoEnd() {
81 __index = __seq->size();
83 __index = std::size_t(0);
88 template <
template <
typename >
class ALLOC >
89 INLINE IdSetIterator< ALLOC >& IdSetIterator< ALLOC >::
90 operator=(
const IdSetIterator< ALLOC >& from) {
92 __index = from.__index;
98 template <
template <
typename >
class ALLOC >
99 INLINE IdSetIterator< ALLOC >& IdSetIterator< ALLOC >::
100 operator=(IdSetIterator< ALLOC >&& from) {
102 __index = from.__index;
108 template <
template <
typename >
class ALLOC >
110 return __seq->operator[](__index);
115 template <
template <
typename >
class ALLOC >
117 operator!=(
const IdSetIterator< ALLOC >& from)
const {
118 return (__index != from.__index) || (__seq != from.__seq);
123 template <
template <
typename >
class ALLOC >
125 operator==(
const IdSetIterator< ALLOC >& from)
const {
131 template <
template <
typename >
class ALLOC >
132 INLINE IdSetIterator< ALLOC >& IdSetIterator< ALLOC >::operator++() {
139 template <
template <
typename >
class ALLOC >
140 INLINE IdSetIterator< ALLOC >& IdSetIterator< ALLOC >::
141 operator+=(
const std::size_t i) {
148 template <
template <
typename >
class ALLOC >
150 IdSetIterator< ALLOC > res(*
this);
157 template <
template <
typename >
class ALLOC >
158 std::size_t IdSetIterator< ALLOC >::pos()
const {
159 if (__seq ==
nullptr)
161 "The IdSet is empty, so its iterators have no position");
162 if (__index >= __seq->size())
164 "the IdSet iterator has no position because it reached " 175 template <
template <
typename >
class ALLOC >
176 INLINE
typename IdSet< ALLOC >::allocator_type
177 IdSet< ALLOC >::getAllocator()
const {
183 template <
template <
typename >
class ALLOC >
184 INLINE IdSet< ALLOC >::IdSet(
185 const typename IdSet< ALLOC >::allocator_type& alloc) :
188 GUM_CONSTRUCTOR(IdSet);
193 template <
template <
typename >
class ALLOC >
194 INLINE IdSet< ALLOC >::IdSet(
195 const std::vector<
NodeId, ALLOC< NodeId > >& ids,
197 const bool ordered_ids,
198 const typename IdSet< ALLOC >::allocator_type& alloc) :
201 __ids.resize(ids.size());
206 std::vector< NodeId, ALLOC< NodeId > > vect(ids);
207 std::sort(vect.begin(), vect.end());
208 for (
const auto id : vect)
211 for (
const auto id : ids)
215 if (!rhs_ids) __nb_lhs_ids = __ids.size();
218 __end_safe.__gotoEnd();
220 GUM_CONSTRUCTOR(IdSet);
225 template <
template <
typename >
class ALLOC >
226 INLINE IdSet< ALLOC >::IdSet(
228 const std::vector<
NodeId, ALLOC< NodeId > >& rhs_ids,
229 const bool ordered_rhs_ids,
230 const typename IdSet< ALLOC >::allocator_type& alloc) :
232 __nb_lhs_ids(
std::size_t(1)), __end_safe(*this) {
233 __ids.resize(rhs_ids.size() + std::size_t(1));
238 if (!ordered_rhs_ids) {
239 std::vector< NodeId, ALLOC< NodeId > > vect(rhs_ids);
240 std::sort(vect.begin(), vect.end());
241 for (
const auto id : vect)
244 for (
const auto id : rhs_ids)
249 __end_safe.__gotoEnd();
251 GUM_CONSTRUCTOR(IdSet);
256 template <
template <
typename >
class ALLOC >
257 INLINE IdSet< ALLOC >::IdSet(
260 const std::vector<
NodeId, ALLOC< NodeId > >& rhs_ids,
261 const bool ordered_lhs_vars,
262 const bool ordered_rhs_ids,
263 const typename IdSet< ALLOC >::allocator_type& alloc) :
265 __nb_lhs_ids(
std::size_t(2)), __end_safe(*this) {
266 __ids.resize(rhs_ids.size() + std::size_t(2));
270 if (!ordered_lhs_vars && (var1 > var2))
std::swap(var1, var2);
276 if (!ordered_rhs_ids) {
277 std::vector< NodeId, ALLOC< NodeId > > vect(rhs_ids);
278 std::sort(vect.begin(), vect.end());
279 for (
const auto id : vect)
282 for (
const auto id : rhs_ids)
287 __end_safe.__gotoEnd();
289 GUM_CONSTRUCTOR(IdSet);
294 template <
template <
typename >
class ALLOC >
295 INLINE IdSet< ALLOC >::IdSet(
299 const std::vector<
NodeId, ALLOC< NodeId > >& rhs_ids,
300 const bool ordered_lhs_vars,
301 const bool ordered_rhs_ids,
302 const typename IdSet< ALLOC >::allocator_type& alloc) :
304 __nb_lhs_ids(
std::size_t(3)), __end_safe(*this) {
305 __ids.resize(rhs_ids.size() + std::size_t(3));
309 if (!ordered_lhs_vars) {
320 if (!ordered_rhs_ids) {
321 std::vector< NodeId, ALLOC< NodeId > > vect(rhs_ids);
322 std::sort(vect.begin(), vect.end());
323 for (
const auto id : vect)
326 for (
const auto id : rhs_ids)
331 __end_safe.__gotoEnd();
333 GUM_CONSTRUCTOR(IdSet);
338 template <
template <
typename >
class ALLOC >
339 INLINE IdSet< ALLOC >::IdSet(
340 const IdSet< ALLOC >& from,
341 const typename IdSet< ALLOC >::allocator_type& alloc) :
343 __ids(from.__ids), __nb_lhs_ids(from.__nb_lhs_ids), __end_safe(*this) {
344 __end_safe.__gotoEnd();
350 template <
template <
typename >
class ALLOC >
351 INLINE IdSet< ALLOC >::IdSet(
const IdSet< ALLOC >& from) :
352 IdSet< ALLOC >(from, from.getAllocator()) {}
356 template <
template <
typename >
class ALLOC >
357 INLINE IdSet< ALLOC >::IdSet(
358 IdSet< ALLOC >&& from,
359 const typename IdSet< ALLOC >::allocator_type& alloc) :
361 __ids(
std::move(from.__ids)), __nb_lhs_ids(from.__nb_lhs_ids),
363 __end_safe.__gotoEnd();
369 template <
template <
typename >
class ALLOC >
370 INLINE IdSet< ALLOC >::IdSet(IdSet< ALLOC >&& from) :
371 IdSet< ALLOC >(
std::move(from), from.getAllocator()) {}
375 template <
template <
typename >
class ALLOC >
376 IdSet< ALLOC >* IdSet< ALLOC >::clone(
377 const typename IdSet< ALLOC >::allocator_type& alloc)
const {
378 ALLOC< IdSet< ALLOC > > allocator(alloc);
379 IdSet< ALLOC >* new_set = allocator.allocate(1);
381 allocator.construct(new_set, *
this, alloc);
383 allocator.deallocate(new_set, 1);
392 template <
template <
typename >
class ALLOC >
393 IdSet< ALLOC >* IdSet< ALLOC >::clone()
const {
394 return clone(this->getAllocator());
399 template <
template <
typename >
class ALLOC >
400 INLINE IdSet< ALLOC >::~IdSet() {
401 GUM_DESTRUCTOR(IdSet);
406 template <
template <
typename >
class ALLOC >
407 INLINE IdSet< ALLOC >& IdSet< ALLOC >::operator=(
const IdSet< ALLOC >& from) {
410 __nb_lhs_ids = from.__nb_lhs_ids;
411 __end_safe.__gotoEnd();
418 template <
template <
typename >
class ALLOC >
419 INLINE IdSet< ALLOC >& IdSet< ALLOC >::operator=(IdSet< ALLOC >&& from) {
421 __ids = std::move(from.__ids);
422 __nb_lhs_ids = from.__nb_lhs_ids;
423 __end_safe.__gotoEnd();
430 template <
template <
typename >
class ALLOC >
431 INLINE
NodeId IdSet< ALLOC >::operator[](
const std::size_t index)
const {
432 return __ids.atPos(index);
437 template <
template <
typename >
class ALLOC >
439 if (__nb_lhs_ids != from.__nb_lhs_ids)
return false;
441 const std::size_t size = __ids.size();
443 if (size != from.__ids.size())
return false;
445 for (std::size_t i = std::size_t(0); i < size; ++i) {
446 if (__ids[i] != from.__ids[i])
return false;
454 template <
template <
typename >
class ALLOC >
461 template <
template <
typename >
class ALLOC >
462 INLINE
typename IdSet< ALLOC >::iterator_safe
463 IdSet< ALLOC >::beginSafe()
const {
464 return IdSetIterator< ALLOC >(*this);
469 template <
template <
typename >
class ALLOC >
470 INLINE
const typename IdSet< ALLOC >::iterator_safe&
471 IdSet< ALLOC >::endSafe()
const {
477 template <
template <
typename >
class ALLOC >
478 INLINE
typename IdSet< ALLOC >::iterator IdSet< ALLOC >::begin()
const {
479 return IdSetIterator< ALLOC >(*this);
484 template <
template <
typename >
class ALLOC >
485 INLINE
const typename IdSet< ALLOC >::iterator& IdSet< ALLOC >::end()
const {
491 template <
template <
typename >
class ALLOC >
492 INLINE
const Sequence< NodeId, ALLOC< NodeId > >& IdSet< ALLOC >::ids()
const {
498 template <
template <
typename >
class ALLOC >
499 IdSet< ALLOC > IdSet< ALLOC >::conditionalIdSet()
const {
500 IdSet< ALLOC >
set(this->getAllocator());
501 const std::size_t size = __ids.size();
502 for (std::size_t i = __nb_lhs_ids; i < size; ++i)
503 set.__ids << __ids[i];
504 set.__end_safe.__gotoEnd();
510 template <
template <
typename >
class ALLOC >
511 void IdSet< ALLOC >::erase(
const NodeId id) {
513 const std::size_t size = __ids.size();
514 std::size_t pos = std::size_t(0);
515 for (; pos < size; ++pos) {
516 if (__ids[pos] ==
id)
break;
522 if (pos < __nb_lhs_ids) --__nb_lhs_ids;
523 __end_safe.__gotoEnd();
529 template <
template <
typename >
class ALLOC >
530 std::string IdSet< ALLOC >::toString()
const {
531 std::stringstream str;
536 for (std::size_t i = std::size_t(0); i < __nb_lhs_ids; ++i) {
545 for (
auto iter = __ids.begin() + __nb_lhs_ids; iter != __ids.end(); ++iter) {
562 template <
template <
typename >
class ALLOC >
563 INLINE std::size_t IdSet< ALLOC >::nbLHSIds()
const {
569 template <
template <
typename >
class ALLOC >
570 INLINE std::size_t IdSet< ALLOC >::nbRHSIds()
const {
571 return __ids.size() - __nb_lhs_ids;
576 template <
template <
typename >
class ALLOC >
577 bool IdSet< ALLOC >::contains(
const IdSet< ALLOC >&
set)
const {
578 if (
set.__ids.size() > __ids.size())
return false;
579 for (
const auto node :
set.__ids) {
580 if (!__ids.exists(node))
return false;
587 template <
template <
typename >
class ALLOC >
588 INLINE
void IdSet< ALLOC >::clear() {
590 __nb_lhs_ids = std::size_t(0);
591 __end_safe.__gotoEnd();
596 template <
template <
typename >
class ALLOC >
597 INLINE std::size_t IdSet< ALLOC >::size()
const {
603 template <
template <
typename >
class ALLOC >
604 INLINE std::size_t IdSet< ALLOC >::pos(
const NodeId id)
const {
605 return __ids.pos(
id);
610 template <
template <
typename >
class ALLOC >
611 INLINE
bool IdSet< ALLOC >::exists(
const NodeId id)
const {
612 return __ids.exists(
id);
617 template <
template <
typename >
class ALLOC >
618 INLINE
bool IdSet< ALLOC >::hasConditioningSet()
const {
619 return __nb_lhs_ids != __ids.size();
624 template <
template <
typename >
class ALLOC >
625 INLINE
bool IdSet< ALLOC >::empty()
const {
626 return __ids.empty();
631 template <
template <
typename >
class ALLOC >
632 std::ostream& operator<<(std::ostream& stream, const IdSet< ALLOC >& idset) {
633 return stream << idset.toString();
640 template <
template <
typename >
class ALLOC >
641 Size HashFunc< learning::IdSet< ALLOC > >::castToSize(
642 const learning::IdSet< ALLOC >& key) {
644 const Sequence< NodeId, ALLOC< NodeId > >& vect = key.ids();
645 const std::size_t size = vect.size();
647 std::size_t i = std::size_t(0);
659 template <
template <
typename >
class ALLOC >
660 INLINE
Size HashFunc< learning::IdSet< ALLOC > >::
661 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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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)