aGrUM  0.16.0
gum::SequenceImplementation< Key, Alloc, Gen > Class Template Reference

The internal class for storing (ordered) sequences of objects. More...

#include <agrum/core/sequence.h>

+ Collaboration diagram for gum::SequenceImplementation< Key, Alloc, Gen >:

Public Member Functions

template<typename OtherAlloc >
INLINE void __copy (const SequenceImplementation< Key, OtherAlloc, Gen > &aSeq)
 
template<typename OtherAlloc >
INLINE SequenceImplementation (const SequenceImplementation< Key, OtherAlloc, Gen > &aSeq)
 
template<typename OtherAlloc >
INLINE SequenceImplementation< Key, Alloc, Gen > & operator= (const SequenceImplementation< Key, OtherAlloc, Gen > &aSeq)
 
template<typename... Args>
INLINE void emplace (Args &&... args)
 
template<typename OtherAlloc >
INLINE bool operator!= (const SequenceImplementation< Key, OtherAlloc, Gen > &k) const
 
template<typename OtherAlloc >
INLINE void __copy (const SequenceImplementation< Key, OtherAlloc, true > &aSeq)
 
template<typename Key, typename Alloc>
 SequenceImplementation (const SequenceImplementation< Key, Alloc, true > &aSeq)
 
template<typename OtherAlloc >
 SequenceImplementation (const SequenceImplementation< Key, OtherAlloc, true > &aSeq)
 
template<typename Key, typename Alloc>
INLINE SequenceImplementation (SequenceImplementation< Key, Alloc, true > &&aSeq)
 
template<typename OtherAlloc >
INLINE SequenceImplementation< Key, Alloc, true > & operator= (const SequenceImplementation< Key, OtherAlloc, true > &aSeq)
 
template<typename OtherAlloc >
bool operator== (const SequenceImplementation< Key, OtherAlloc, true > &k) const
 
template<typename OtherAlloc >
INLINE bool operator!= (const SequenceImplementation< Key, OtherAlloc, true > &k) const
 
Destructor
 ~SequenceImplementation () noexcept
 Class destructor. More...
 
Iterators
iterator_safe beginSafe () const
 Returns a safe begin iterator. More...
 
iterator_safe rbeginSafe () const
 Returns a safe rbegin iterator. More...
 
const iterator_safeendSafe () const noexcept
 Returns the safe end iterator. More...
 
const iterator_saferendSafe () const noexcept
 Returns the safe rend iterator. More...
 
iterator begin () const
 Returns an unsafe begin iterator. More...
 
iterator rbegin () const
 Returns an unsafe rbegin iterator. More...
 
const iteratorend () const noexcept
 Returns the unsafe end iterator. More...
 
const iteratorrend () const noexcept
 Returns the unsafe rend iterator. More...
 
Operators
SequenceImplementation< Key, Alloc, Gen > & operator<< (const Key &k)
 Insert k at the end of the sequence (synonym for insert). More...
 
SequenceImplementation< Key, Alloc, Gen > & operator<< (Key &&k)
 Insert k at the end of the sequence (synonym for insert). More...
 
SequenceImplementation< Key, Alloc, Gen > & operator>> (const Key &k)
 Remove k in the sequence (synonym for erase). More...
 
const Key & operator[] (Idx i) const
 Returns the element at position i (synonym for atPos). More...
 
template<typename OtherAlloc >
bool operator== (const SequenceImplementation< Key, OtherAlloc, Gen > &k) const
 Returns true if the content of k equals that of *this. More...
 
template<typename OtherAlloc >
bool operator!= (const SequenceImplementation< Key, OtherAlloc, Gen > &k) const
 Returns true if the content of k is different from that of *this. More...
 
Accessors / Modifiers
void clear ()
 Clear the sequence. More...
 
Size size () const noexcept
 Returns the size of the sequence. More...
 
bool empty () const noexcept
 Return true if empty. More...
 
bool exists (const Key &k) const
 Check the existence of k in the sequence. More...
 
void insert (const Key &k)
 Insert an element at the end of the sequence. More...
 
void insert (Key &&k)
 Move an element at the end of the sequence. More...
 
template<typename... Args>
void emplace (Args &&... args)
 Emplace a new element in the sequence. More...
 
void erase (const Key &k)
 Remove an element from the sequence. More...
 
void erase (const iterator_safe &k)
 Remove from the sequence the element pointed to by the iterator. More...
 
const Key & atPos (Idx i) const
 Returns the object at the pos i. More...
 
Idx pos (const Key &key) const
 Returns the position of the object passed in argument (if it exists). More...
 
void setAtPos (Idx i, const Key &newKey)
 Change the value. More...
 
void setAtPos (Idx i, Key &&newKey)
 Change the value. More...
 
void swap (Idx i, Idx j)
 Swap index. More...
 
const Key & front () const
 Returns the first element of the element. More...
 
const Key & back () const
 Returns the last element of the sequence. More...
 
std::string toString () const
 Displays the content of the sequence. More...
 
void resize (Size new_size)
 Modifies the size of the internal structures of the sequence. More...
 

Public Types

using value_type = Key
 Types for STL compliance. More...
 
using reference = Key &
 Types for STL compliance. More...
 
using const_reference = const Key &
 Types for STL compliance. More...
 
using pointer = Key *
 Types for STL compliance. More...
 
using const_pointer = const Key *
 Types for STL compliance. More...
 
using size_type = std::size_t
 Types for STL compliance. More...
 
using difference_type = std::ptrdiff_t
 Types for STL compliance. More...
 
using allocator_type = Alloc
 Types for STL compliance. More...
 
using iterator = SequenceIterator< Key >
 Types for STL compliance. More...
 
using const_iterator = SequenceIterator< Key >
 Types for STL compliance. More...
 
using iterator_safe = SequenceIteratorSafe< Key >
 Types for STL compliance. More...
 
using const_iterator_safe = SequenceIteratorSafe< Key >
 Types for STL compliance. More...
 

Friends

template<typename K , typename A , bool >
class SequenceImplementation
 Friends to speed up access. More...
 
class SequenceIteratorSafe< Key >
 Friends to speed up access. More...
 
class Sequence< Key, Alloc >
 Friends to speed up access. More...
 

Detailed Description

template<typename Key, typename Alloc, bool Gen>
class gum::SequenceImplementation< Key, Alloc, Gen >

The internal class for storing (ordered) sequences of objects.

A SequenceImplementation<Key,Alloc,bool Gen> is a specialized version of of a Sequence<Key,Alloc>. It shall not be used by itself but rather through the Sequence class. A SequenceImplementation is quite similar to a vector<Key> in that it stores an ordered set of elements. The main difference between these two data structures lies in the fact that, given a key, it is possible to retrieve from a SequenceImplementation the index in the vector where the key lies in O(1). As a result, it is not possible to insert a given element twice in the sequence, that is, all the Keys must be different.

When the Boolean template parameter gen is false, SequenceImplementation implements a very generic sequence. This allows having Sequences containing elements of virtually any class or type. When the Boolean gen is equal to true, the SequenceImplementation shall contain only scalar types (integers, floats, pointers, etc). As such, knowning that the element is a scalar enables to optimize the code of the sequences. Determining whether gen should be set to true or false is not left to the developper but is determined by the compiler itself at compile time.

Template Parameters
KeyThe elements type stored in the sequence.
AllocThe values allocator.
GenUsed for meta-programation.

Definition at line 90 of file sequence.h.

Member Typedef Documentation

◆ allocator_type

template<typename Key, typename Alloc, bool Gen>
using gum::SequenceImplementation< Key, Alloc, Gen >::allocator_type = Alloc

Types for STL compliance.

Definition at line 109 of file sequence.h.

◆ const_iterator

template<typename Key, typename Alloc, bool Gen>
using gum::SequenceImplementation< Key, Alloc, Gen >::const_iterator = SequenceIterator< Key >

Types for STL compliance.

Definition at line 111 of file sequence.h.

◆ const_iterator_safe

template<typename Key, typename Alloc, bool Gen>
using gum::SequenceImplementation< Key, Alloc, Gen >::const_iterator_safe = SequenceIteratorSafe< Key >

Types for STL compliance.

Definition at line 113 of file sequence.h.

◆ const_pointer

template<typename Key, typename Alloc, bool Gen>
using gum::SequenceImplementation< Key, Alloc, Gen >::const_pointer = const Key*

Types for STL compliance.

Definition at line 106 of file sequence.h.

◆ const_reference

template<typename Key, typename Alloc, bool Gen>
using gum::SequenceImplementation< Key, Alloc, Gen >::const_reference = const Key&

Types for STL compliance.

Definition at line 104 of file sequence.h.

◆ difference_type

template<typename Key, typename Alloc, bool Gen>
using gum::SequenceImplementation< Key, Alloc, Gen >::difference_type = std::ptrdiff_t

Types for STL compliance.

Definition at line 108 of file sequence.h.

◆ iterator

template<typename Key, typename Alloc, bool Gen>
using gum::SequenceImplementation< Key, Alloc, Gen >::iterator = SequenceIterator< Key >

Types for STL compliance.

Definition at line 110 of file sequence.h.

◆ iterator_safe

template<typename Key, typename Alloc, bool Gen>
using gum::SequenceImplementation< Key, Alloc, Gen >::iterator_safe = SequenceIteratorSafe< Key >

Types for STL compliance.

Definition at line 112 of file sequence.h.

◆ pointer

template<typename Key, typename Alloc, bool Gen>
using gum::SequenceImplementation< Key, Alloc, Gen >::pointer = Key*

Types for STL compliance.

Definition at line 105 of file sequence.h.

◆ reference

template<typename Key, typename Alloc, bool Gen>
using gum::SequenceImplementation< Key, Alloc, Gen >::reference = Key&

Types for STL compliance.

Definition at line 103 of file sequence.h.

◆ size_type

template<typename Key, typename Alloc, bool Gen>
using gum::SequenceImplementation< Key, Alloc, Gen >::size_type = std::size_t

Types for STL compliance.

Definition at line 107 of file sequence.h.

◆ value_type

template<typename Key, typename Alloc, bool Gen>
using gum::SequenceImplementation< Key, Alloc, Gen >::value_type = Key

Types for STL compliance.

Definition at line 102 of file sequence.h.

Constructor & Destructor Documentation

◆ SequenceImplementation() [1/9]

template<typename Key , typename Alloc >
INLINE gum::SequenceImplementation< Key, Alloc >::SequenceImplementation ( Size  size_param = HashTableConst::default_size)
private

Default constructor.

Parameters
size_paramThe intial size of the gum::SequenceImplementation.

Definition at line 294 of file sequence_tpl.h.

295  :
296  __h(size_param),
297  __end_safe{*this}, __rend_safe{*this} {
298  // for debugging purposes
299  GUM_CONSTRUCTOR(SequenceImplementation);
300  __rend_safe.__setAtRend();
301  __update_end();
302  }
friend class SequenceImplementation
Friends to speed up access.
Definition: sequence.h:94
HashTable< Key, Idx, Alloc > __h
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:500
SequenceIteratorSafe< Key > __rend_safe
Stores the rend iterator for fast access.
Definition: sequence.h:513
void __update_end() noexcept
A method to update the end iterator after changes in the sequence.
Definition: sequence_tpl.h:265
SequenceIteratorSafe< Key > __end_safe
Stores the end iterator for fast access.
Definition: sequence.h:510

◆ SequenceImplementation() [2/9]

template<typename Key, typename Alloc >
INLINE gum::SequenceImplementation< Key, Alloc >::SequenceImplementation ( std::initializer_list< Key >  list)
private

Initializer list constructor.

Parameters
listThe initializer list.

Definition at line 306 of file sequence_tpl.h.

307  :
308  __end_safe{*this},
309  __rend_safe{*this} {
310  GUM_CONSTRUCTOR(SequenceImplementation);
311  __rend_safe.__setAtRend();
312  for (const auto& elt : list) {
313  insert(elt); // performs the __update_end ()
314  }
315  }
friend class SequenceImplementation
Friends to speed up access.
Definition: sequence.h:94
SequenceIteratorSafe< Key > __rend_safe
Stores the rend iterator for fast access.
Definition: sequence.h:513
SequenceIteratorSafe< Key > __end_safe
Stores the end iterator for fast access.
Definition: sequence.h:510
void insert(const Key &k)
Insert an element at the end of the sequence.
Definition: sequence_tpl.h:408

◆ SequenceImplementation() [3/9]

template<typename Key, typename Alloc, bool Gen>
INLINE gum::SequenceImplementation< Key, Alloc, Gen >::SequenceImplementation ( const SequenceImplementation< Key, Alloc, Gen > &  aSeq)
private

Copy constructor.

Parameters
aSeqThe sequence the elements of which will be copied.
Warning
The elements of the newly constructed sequence are copies of those in aSeq.

Definition at line 319 of file sequence_tpl.h.

320  :
321  __end_safe{*this},
322  __rend_safe{*this} {
323  // for debugging purposes
324  GUM_CONS_CPY(SequenceImplementation);
325  __rend_safe.__setAtRend();
326  __copy(aSeq); // performs the __update_end ()
327  }
friend class SequenceImplementation
Friends to speed up access.
Definition: sequence.h:94
SequenceIteratorSafe< Key > __rend_safe
Stores the rend iterator for fast access.
Definition: sequence.h:513
void __copy(const SequenceImplementation< Key, OtherAlloc, Gen > &aSeq)
Clears the current sequence and fill it with copies the element of aSeq.
SequenceIteratorSafe< Key > __end_safe
Stores the end iterator for fast access.
Definition: sequence.h:510

◆ SequenceImplementation() [4/9]

template<typename Key, typename Alloc, bool Gen>
template<typename OtherAlloc >
gum::SequenceImplementation< Key, Alloc, Gen >::SequenceImplementation ( const SequenceImplementation< Key, OtherAlloc, Gen > &  aSeq)
private

Generalised copy constructor.

Template Parameters
OtherAllocThe other gum::SequenceImplementation allocator.
Parameters
aSeqThe sequence the elements of which will be copied.
Warning
The elements of the newly constructed sequence are copies of those in aSeq.

◆ SequenceImplementation() [5/9]

template<typename Key, typename Alloc, bool Gen>
INLINE gum::SequenceImplementation< Key, Alloc, Gen >::SequenceImplementation ( SequenceImplementation< Key, Alloc, Gen > &&  aSeq)
private

Move constructor.

Parameters
aSeqThe gum::SequenceImplementation to move/

Definition at line 344 of file sequence_tpl.h.

345  :
346  __h(std::move(aSeq.__h)),
347  __v(std::move(aSeq.__v)), __end_safe{*this}, __rend_safe{*this} {
348  // for debugging purposes
349  GUM_CONS_MOV(SequenceImplementation);
350  __rend_safe.__setAtRend();
351  __update_end();
352  }
friend class SequenceImplementation
Friends to speed up access.
Definition: sequence.h:94
HashTable< Key, Idx, Alloc > __h
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:500
SequenceIteratorSafe< Key > __rend_safe
Stores the rend iterator for fast access.
Definition: sequence.h:513
void __update_end() noexcept
A method to update the end iterator after changes in the sequence.
Definition: sequence_tpl.h:265
std::vector< Key *, typename Alloc::template rebind< Key *>::other > __v
The set of the elements stored into the sequence.
Definition: sequence.h:503
SequenceIteratorSafe< Key > __end_safe
Stores the end iterator for fast access.
Definition: sequence.h:510

◆ ~SequenceImplementation()

template<typename Key , typename Alloc >
gum::SequenceImplementation< Key, Alloc >::~SequenceImplementation ( )
noexcept

Class destructor.

Definition at line 357 of file sequence_tpl.h.

357  {
358  GUM_DESTRUCTOR(SequenceImplementation);
359  }
friend class SequenceImplementation
Friends to speed up access.
Definition: sequence.h:94

◆ SequenceImplementation() [6/9]

template<typename Key, typename Alloc, bool Gen>
template<typename OtherAlloc >
INLINE gum::SequenceImplementation< Key, Alloc, Gen >::SequenceImplementation ( const SequenceImplementation< Key, OtherAlloc, Gen > &  aSeq)

Definition at line 332 of file sequence_tpl.h.

333  :
334  __end_safe{*this},
335  __rend_safe{*this} {
336  // for debugging purposes
337  GUM_CONS_CPY(SequenceImplementation);
338  __rend_safe.__setAtRend();
339  __copy(aSeq); // performs the __update_end ()
340  }
friend class SequenceImplementation
Friends to speed up access.
Definition: sequence.h:94
SequenceIteratorSafe< Key > __rend_safe
Stores the rend iterator for fast access.
Definition: sequence.h:513
void __copy(const SequenceImplementation< Key, OtherAlloc, Gen > &aSeq)
Clears the current sequence and fill it with copies the element of aSeq.
SequenceIteratorSafe< Key > __end_safe
Stores the end iterator for fast access.
Definition: sequence.h:510

◆ SequenceImplementation() [7/9]

template<typename Key, typename Alloc, bool Gen>
template<typename Key, typename Alloc>
gum::SequenceImplementation< Key, Alloc, Gen >::SequenceImplementation ( const SequenceImplementation< Key, Alloc, true > &  aSeq)

Definition at line 753 of file sequence_tpl.h.

754  :
755  __h(aSeq.__h),
756  __v(aSeq.__v), __end_safe{*this}, __rend_safe{*this} {
757  // for debugging purposes
758  GUM_CONS_CPY(SequenceImplementation);
759  __rend_safe.__setAtRend();
760  __end_safe.__setAtEnd();
761  }
friend class SequenceImplementation
Friends to speed up access.
Definition: sequence.h:94
HashTable< Key, Idx, Alloc > __h
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:500
SequenceIteratorSafe< Key > __rend_safe
Stores the rend iterator for fast access.
Definition: sequence.h:513
std::vector< Key *, typename Alloc::template rebind< Key *>::other > __v
The set of the elements stored into the sequence.
Definition: sequence.h:503
SequenceIteratorSafe< Key > __end_safe
Stores the end iterator for fast access.
Definition: sequence.h:510

◆ SequenceImplementation() [8/9]

template<typename Key, typename Alloc, bool Gen>
template<typename OtherAlloc >
gum::SequenceImplementation< Key, Alloc, Gen >::SequenceImplementation ( const SequenceImplementation< Key, OtherAlloc, true > &  aSeq)

Definition at line 766 of file sequence_tpl.h.

767  :
768  __h(aSeq.size() / 2),
769  __end_safe{*this}, __rend_safe{*this} {
770  // for debugging purposes
771  GUM_CONS_CPY(SequenceImplementation);
772  __rend_safe.__setAtRend();
773  __copy(aSeq);
774  }
friend class SequenceImplementation
Friends to speed up access.
Definition: sequence.h:94
HashTable< Key, Idx, Alloc > __h
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:500
SequenceIteratorSafe< Key > __rend_safe
Stores the rend iterator for fast access.
Definition: sequence.h:513
void __copy(const SequenceImplementation< Key, OtherAlloc, Gen > &aSeq)
Clears the current sequence and fill it with copies the element of aSeq.
SequenceIteratorSafe< Key > __end_safe
Stores the end iterator for fast access.
Definition: sequence.h:510

◆ SequenceImplementation() [9/9]

template<typename Key, typename Alloc, bool Gen>
template<typename Key, typename Alloc>
INLINE gum::SequenceImplementation< Key, Alloc, Gen >::SequenceImplementation ( SequenceImplementation< Key, Alloc, true > &&  aSeq)

Definition at line 778 of file sequence_tpl.h.

779  :
780  __h(std::move(aSeq.__h)),
781  __v(std::move(aSeq.__v)), __end_safe{*this}, __rend_safe{*this} {
782  // for debugging purposes
783  GUM_CONS_MOV(SequenceImplementation);
784  __rend_safe.__setAtRend();
785  __end_safe.__setAtEnd();
786  }
friend class SequenceImplementation
Friends to speed up access.
Definition: sequence.h:94
HashTable< Key, Idx, Alloc > __h
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:500
SequenceIteratorSafe< Key > __rend_safe
Stores the rend iterator for fast access.
Definition: sequence.h:513
std::vector< Key *, typename Alloc::template rebind< Key *>::other > __v
The set of the elements stored into the sequence.
Definition: sequence.h:503
SequenceIteratorSafe< Key > __end_safe
Stores the end iterator for fast access.
Definition: sequence.h:510

Member Function Documentation

◆ __copy() [1/3]

template<typename Key, typename Alloc, bool Gen>
template<typename OtherAlloc >
INLINE void gum::SequenceImplementation< Key, Alloc, Gen >::__copy ( const SequenceImplementation< Key, OtherAlloc, Gen > &  aSeq)

Definition at line 280 of file sequence_tpl.h.

281  {
282  clear();
283 
284  for (Size i = 0; i < aSeq.size(); ++i) {
285  Key& new_key = const_cast< Key& >(__h.insert(*(aSeq.__v[i]), i).first);
286  __v.push_back(&new_key);
287  }
288 
289  __update_end();
290  }
void clear()
Clear the sequence.
Definition: sequence_tpl.h:271
HashTable< Key, Idx, Alloc > __h
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:500
void __update_end() noexcept
A method to update the end iterator after changes in the sequence.
Definition: sequence_tpl.h:265
std::vector< Key *, typename Alloc::template rebind< Key *>::other > __v
The set of the elements stored into the sequence.
Definition: sequence.h:503
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.

◆ __copy() [2/3]

template<typename Key, typename Alloc, bool Gen>
template<typename OtherAlloc >
void gum::SequenceImplementation< Key, Alloc, Gen >::__copy ( const SequenceImplementation< Key, OtherAlloc, Gen > &  aSeq)
private

Clears the current sequence and fill it with copies the element of aSeq.

Template Parameters
OtherAllocThe other gum::SequenceImplementation allocator.
Parameters
aSeqThe gum::SequenceImplementation to copy.

◆ __copy() [3/3]

template<typename Key, typename Alloc, bool Gen>
template<typename OtherAlloc >
INLINE void gum::SequenceImplementation< Key, Alloc, Gen >::__copy ( const SequenceImplementation< Key, OtherAlloc, true > &  aSeq)

Definition at line 714 of file sequence_tpl.h.

715  {
716  clear();
717 
718  for (Size i = 0; i < aSeq.size(); ++i) {
719  __h.insert(aSeq.__v[i], i);
720  __v.push_back(aSeq.__v[i]);
721  }
722 
723  __update_end();
724  }
void clear()
Clear the sequence.
Definition: sequence_tpl.h:271
HashTable< Key, Idx, Alloc > __h
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:500
void __update_end() noexcept
A method to update the end iterator after changes in the sequence.
Definition: sequence_tpl.h:265
std::vector< Key *, typename Alloc::template rebind< Key *>::other > __v
The set of the elements stored into the sequence.
Definition: sequence.h:503
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.

◆ __insert()

template<typename Key, typename Alloc, bool Gen>
void gum::SequenceImplementation< Key, Alloc, Gen >::__insert ( HashTableBucket< Key, Idx > &&  bucket)
private

Insert an element at the end of the sequence.

Parameters
bucketThe bucket holing the store to insert.

◆ __update_end()

template<typename Key , typename Alloc >
INLINE void gum::SequenceImplementation< Key, Alloc >::__update_end ( )
privatenoexcept

A method to update the end iterator after changes in the sequence.

Definition at line 265 of file sequence_tpl.h.

265  {
266  __end_safe.__setAtEnd();
267  }
SequenceIteratorSafe< Key > __end_safe
Stores the end iterator for fast access.
Definition: sequence.h:510

◆ atPos()

template<typename Key , typename Alloc >
INLINE const Key & gum::SequenceImplementation< Key, Alloc >::atPos ( Idx  i) const

Returns the object at the pos i.

Parameters
iThe position of the element to return.
Returns
Returns the object at the pos i.
Exceptions
NotFoundRaised if the element does not exist.

Definition at line 500 of file sequence_tpl.h.

Referenced by gum::ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ >::operator[]().

500  {
501  if (i >= __h.size()) {
502  GUM_ERROR(OutOfBounds,
503  "index " << i << " for a sequence of size" << __h.size());
504  }
505 
506  return *(__v[i]);
507  }
Size size() const noexcept
Returns the number of elements stored into the hashtable.
HashTable< Key, Idx, Alloc > __h
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:500
std::vector< Key *, typename Alloc::template rebind< Key *>::other > __v
The set of the elements stored into the sequence.
Definition: sequence.h:503
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the caller graph for this function:

◆ back()

template<typename Key , typename Alloc >
INLINE const Key & gum::SequenceImplementation< Key, Alloc >::back ( ) const

Returns the last element of the sequence.

Returns
Returns the last element of the sequence.
Exceptions
NotFoundRaised if the sequence is empty.

Definition at line 568 of file sequence_tpl.h.

Referenced by gum::prm::StructuredInference< GUM_SCALAR >::__removeBarrenNodes(), and gum::DiGraph::__topologicalOrder().

568  {
569  return atPos(size() - 1);
570  }
Size size() const noexcept
Returns the size of the sequence.
Definition: sequence_tpl.h:38
const Key & atPos(Idx i) const
Returns the object at the pos i.
Definition: sequence_tpl.h:500
+ Here is the caller graph for this function:

◆ begin()

template<typename Key , typename Alloc >
INLINE SequenceIterator< Key > gum::SequenceImplementation< Key, Alloc >::begin ( ) const

Returns an unsafe begin iterator.

Returns
Returns an unsafe begin iterator.

Definition at line 657 of file sequence_tpl.h.

Referenced by gum::InfluenceDiagramGenerator< GUM_SCALAR >::__checkTemporalOrder(), and gum::InfluenceDiagram< GUM_SCALAR >::decisionOrderExists().

657  {
658  return SequenceIterator< Key >{*this};
659  }
+ Here is the caller graph for this function:

◆ beginSafe()

template<typename Key , typename Alloc >
INLINE SequenceIteratorSafe< Key > gum::SequenceImplementation< Key, Alloc >::beginSafe ( ) const

Returns a safe begin iterator.

Returns
Returns a safe begin iterator.

Definition at line 627 of file sequence_tpl.h.

Referenced by gum::FMDP< double >::beginActions(), gum::TaxiSimulator::beginActions(), gum::FactorySimulator::beginActions(), and gum::ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ >::beginSafe().

627  {
628  return SequenceIteratorSafe< Key >{*this};
629  }
friend class SequenceIteratorSafe< Key >
Friends to speed up access.
Definition: sequence.h:95
+ Here is the caller graph for this function:

◆ clear()

template<typename Key , typename Alloc >
INLINE void gum::SequenceImplementation< Key, Alloc >::clear ( )

Clear the sequence.

Definition at line 271 of file sequence_tpl.h.

Referenced by gum::GibbsOperator< GUM_SCALAR >::__updateSamplingNodes(), gum::SequenceImplementation< gum::prm::PRMClassElement< double > *, std::allocator< gum::prm::PRMClassElement< double > *>, std::is_scalar< gum::prm::PRMClassElement< double > *>::value >::resize(), and gum::DiGraph::topologicalOrder().

271  {
272  __h.clear();
273  __v.clear();
274  __update_end();
275  }
HashTable< Key, Idx, Alloc > __h
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:500
void __update_end() noexcept
A method to update the end iterator after changes in the sequence.
Definition: sequence_tpl.h:265
void clear()
Removes all the elements in the hash table.
std::vector< Key *, typename Alloc::template rebind< Key *>::other > __v
The set of the elements stored into the sequence.
Definition: sequence.h:503
+ Here is the caller graph for this function:

◆ emplace() [1/2]

template<typename Key, typename Alloc, bool Gen>
template<typename... Args>
void gum::SequenceImplementation< Key, Alloc, Gen >::emplace ( Args &&...  args)

Emplace a new element in the sequence.

The emplace is a method that allows to construct directly an element of type Key by passing to its constructor all the arguments it needs.

Template Parameters
ArgsThe arguments types passed to the constructor.
Parameters
argsThe arguments passed to the constructor.
Exceptions
DuplicateElementRaised if the sequence contains already k.

◆ emplace() [2/2]

template<typename Key , typename Alloc >
template<typename... Args>
INLINE void gum::SequenceImplementation< Key, Alloc >::emplace ( Args &&...  args)

Definition at line 427 of file sequence_tpl.h.

427  {
428  Key key(std::forward< Args >(args)...);
429  Key& new_key =
430  const_cast< Key& >(__h.insert(std::move(key), __h.size()).first);
431  __v.push_back(&new_key);
432  __update_end();
433  }
Size size() const noexcept
Returns the number of elements stored into the hashtable.
HashTable< Key, Idx, Alloc > __h
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:500
void __update_end() noexcept
A method to update the end iterator after changes in the sequence.
Definition: sequence_tpl.h:265
std::vector< Key *, typename Alloc::template rebind< Key *>::other > __v
The set of the elements stored into the sequence.
Definition: sequence.h:503
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.

◆ empty()

template<typename Key , typename Alloc >
INLINE bool gum::SequenceImplementation< Key, Alloc >::empty ( ) const
noexcept

Return true if empty.

Returns
Return true if empty.

Definition at line 44 of file sequence_tpl.h.

Referenced by gum::SequenceImplementation< gum::prm::PRMClassElement< double > *, std::allocator< gum::prm::PRMClassElement< double > *>, std::is_scalar< gum::prm::PRMClassElement< double > *>::value >::empty().

44  {
45  return __h.empty();
46  }
HashTable< Key, Idx, Alloc > __h
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:500
bool empty() const noexcept
Indicates whether the hash table is empty.
+ Here is the caller graph for this function:

◆ end()

template<typename Key , typename Alloc >
INLINE const SequenceIterator< Key > & gum::SequenceImplementation< Key, Alloc >::end ( ) const
noexcept

Returns the unsafe end iterator.

Returns
Returns the unsafe end iterator.

Definition at line 664 of file sequence_tpl.h.

Referenced by gum::InfluenceDiagramGenerator< GUM_SCALAR >::__checkTemporalOrder(), and gum::InfluenceDiagram< GUM_SCALAR >::decisionOrderExists().

664  {
665  return __end_safe;
666  }
SequenceIteratorSafe< Key > __end_safe
Stores the end iterator for fast access.
Definition: sequence.h:510
+ Here is the caller graph for this function:

◆ endSafe()

template<typename Key , typename Alloc >
INLINE const SequenceIteratorSafe< Key > & gum::SequenceImplementation< Key, Alloc >::endSafe ( ) const
noexcept

Returns the safe end iterator.

Returns
Returns the safe end iterator.

Definition at line 634 of file sequence_tpl.h.

Referenced by gum::FMDP< double >::endActions(), gum::TaxiSimulator::endActions(), gum::FactorySimulator::endActions(), and gum::ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ >::endSafe().

634  {
635  return __end_safe;
636  }
SequenceIteratorSafe< Key > __end_safe
Stores the end iterator for fast access.
Definition: sequence.h:510
+ Here is the caller graph for this function:

◆ erase() [1/2]

template<typename Key, typename Alloc , bool Gen>
INLINE void gum::SequenceImplementation< Key, Alloc, Gen >::erase ( const Key &  k)

Remove an element from the sequence.

If the element cannot be found, the function does nothing. In particular, it throws no exception. Complexity \(o(n)\) (need to change the position of at most the n elements).

Parameters
kThe element to remove.

Definition at line 453 of file sequence_tpl.h.

Referenced by gum::prm::StructuredInference< GUM_SCALAR >::__removeBarrenNodes(), gum::MultiDimFunctionGraphManager< bool, ExactTerminalNodePolicy >::clean(), gum::SequenceImplementation< gum::prm::PRMClassElement< double > *, std::allocator< gum::prm::PRMClassElement< double > *>, std::is_scalar< gum::prm::PRMClassElement< double > *>::value >::erase(), and gum::SequenceImplementation< gum::prm::PRMClassElement< double > *, std::allocator< gum::prm::PRMClassElement< double > *>, std::is_scalar< gum::prm::PRMClassElement< double > *>::value >::operator=().

453  {
454  // get the position of the element to remove
455  Idx pos;
456 
457  try {
458  pos = __h[k];
459  } catch (NotFound&) { return; }
460 
461  // erase the element
462  __v.erase(__v.begin() + pos);
463  for (Idx i = pos, nb_elts = __h.size() - 1; i < nb_elts; ++i) {
464  --__h[*(__v[i])];
465  }
466  __h.erase(k);
467 
468  __update_end();
469  }
Idx pos(const Key &key) const
Returns the position of the object passed in argument (if it exists).
Definition: sequence_tpl.h:518
Size size() const noexcept
Returns the number of elements stored into the hashtable.
void erase(const Key &key)
Removes a given element from the hash table.
HashTable< Key, Idx, Alloc > __h
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:500
void __update_end() noexcept
A method to update the end iterator after changes in the sequence.
Definition: sequence_tpl.h:265
std::vector< Key *, typename Alloc::template rebind< Key *>::other > __v
The set of the elements stored into the sequence.
Definition: sequence.h:503
+ Here is the caller graph for this function:

◆ erase() [2/2]

template<typename Key, typename Alloc >
INLINE void gum::SequenceImplementation< Key, Alloc >::erase ( const iterator_safe k)

Remove from the sequence the element pointed to by the iterator.

If the element cannot be found, the function does nothing. In particular, it throws no exception. Complexity \(o(n)\) (need to change the position of at most the n elements)

Parameters
kThe iterator poiting to the element to remove.

Definition at line 474 of file sequence_tpl.h.

474  {
475  if (iter.pos() >= size()) return;
476 
477  // erase the element
478  Idx pos = iter.pos();
479  Key* key = __v[pos];
480  __v.erase(__v.begin() + pos);
481 
482  for (Idx i = pos, nb_elts = __h.size() - 1; i < nb_elts; ++i) {
483  --__h[*(__v[i])];
484  }
485  __h.erase(*key);
486 
487  __update_end();
488  }
Idx pos(const Key &key) const
Returns the position of the object passed in argument (if it exists).
Definition: sequence_tpl.h:518
Size size() const noexcept
Returns the number of elements stored into the hashtable.
Size size() const noexcept
Returns the size of the sequence.
Definition: sequence_tpl.h:38
void erase(const Key &key)
Removes a given element from the hash table.
HashTable< Key, Idx, Alloc > __h
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:500
void __update_end() noexcept
A method to update the end iterator after changes in the sequence.
Definition: sequence_tpl.h:265
std::vector< Key *, typename Alloc::template rebind< Key *>::other > __v
The set of the elements stored into the sequence.
Definition: sequence.h:503

◆ exists()

template<typename Key, typename Alloc , bool Gen>
INLINE bool gum::SequenceImplementation< Key, Alloc >::exists ( const Key &  k) const

Check the existence of k in the sequence.

The complexity is \(o(1)\).

Parameters
kThe key to check for existence.
Returns
Returns true if k is in the gum::SequenceImplementation.

Definition at line 402 of file sequence_tpl.h.

Referenced by gum::DiGraph::__topologicalOrder(), gum::ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ >::exists(), gum::SequenceImplementation< gum::prm::PRMClassElement< double > *, std::allocator< gum::prm::PRMClassElement< double > *>, std::is_scalar< gum::prm::PRMClassElement< double > *>::value >::exists(), and gum::SequenceImplementation< gum::prm::PRMClassElement< double > *, std::allocator< gum::prm::PRMClassElement< double > *>, std::is_scalar< gum::prm::PRMClassElement< double > *>::value >::operator=().

402  {
403  return __h.exists(k);
404  }
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
HashTable< Key, Idx, Alloc > __h
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:500
+ Here is the caller graph for this function:

◆ front()

template<typename Key , typename Alloc >
INLINE const Key & gum::SequenceImplementation< Key, Alloc >::front ( ) const

Returns the first element of the element.

Returns
Returns the first element of the element.
Exceptions
NotFoundRaised if the sequence is empty.

Definition at line 562 of file sequence_tpl.h.

562  {
563  return atPos(0);
564  }
const Key & atPos(Idx i) const
Returns the object at the pos i.
Definition: sequence_tpl.h:500

◆ insert() [1/2]

template<typename Key, typename Alloc , bool Gen>
INLINE void gum::SequenceImplementation< Key, Alloc, Gen >::insert ( const Key &  k)

Insert an element at the end of the sequence.

The complexity is \(o(1)\).

Parameters
kThe element to insert.
Exceptions
DuplicateElementRaised if the sequence contains already k.

Definition at line 408 of file sequence_tpl.h.

Referenced by gum::prm::SVED< GUM_SCALAR >::__initElimOrder(), gum::prm::SVE< GUM_SCALAR >::__initElimOrder(), gum::prm::StructuredInference< GUM_SCALAR >::__removeBarrenNodes(), gum::DiGraph::__topologicalOrder(), gum::GibbsOperator< GUM_SCALAR >::__updateSamplingNodes(), gum::InfluenceDiagram< GUM_SCALAR >::_getChildrenDecision(), gum::ActionSet::ActionSet(), gum::ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ >::ArgMaxSet(), gum::ActionSet::operator=(), gum::SequenceImplementation< gum::prm::PRMClassElement< double > *, std::allocator< gum::prm::PRMClassElement< double > *>, std::is_scalar< gum::prm::PRMClassElement< double > *>::value >::operator=(), and gum::TaxiSimulator::TaxiSimulator().

408  {
409  // k will be added at the end. Insert the new key into the hashtable
410  Key& new_key = const_cast< Key& >(__h.insert(k, __h.size()).first);
411  __v.push_back(&new_key);
412  __update_end();
413  }
Size size() const noexcept
Returns the number of elements stored into the hashtable.
HashTable< Key, Idx, Alloc > __h
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:500
void __update_end() noexcept
A method to update the end iterator after changes in the sequence.
Definition: sequence_tpl.h:265
std::vector< Key *, typename Alloc::template rebind< Key *>::other > __v
The set of the elements stored into the sequence.
Definition: sequence.h:503
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
+ Here is the caller graph for this function:

◆ insert() [2/2]

template<typename Key, typename Alloc , bool Gen>
INLINE void gum::SequenceImplementation< Key, Alloc, Gen >::insert ( Key &&  k)

Move an element at the end of the sequence.

The complexity is \(o(1)\).

Parameters
kThe element to insert.
Exceptions
DuplicateElementRaised if the sequence contains already k.

Definition at line 417 of file sequence_tpl.h.

417  {
418  // k will be added at the end. Insert the new key into the hashtable
419  Key& new_key = const_cast< Key& >(__h.insert(std::move(k), __h.size()).first);
420  __v.push_back(&new_key);
421  __update_end();
422  }
Size size() const noexcept
Returns the number of elements stored into the hashtable.
HashTable< Key, Idx, Alloc > __h
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:500
void __update_end() noexcept
A method to update the end iterator after changes in the sequence.
Definition: sequence_tpl.h:265
std::vector< Key *, typename Alloc::template rebind< Key *>::other > __v
The set of the elements stored into the sequence.
Definition: sequence.h:503
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.

◆ operator!=() [1/3]

template<typename Key, typename Alloc, bool Gen>
template<typename OtherAlloc >
bool gum::SequenceImplementation< Key, Alloc, Gen >::operator!= ( const SequenceImplementation< Key, OtherAlloc, Gen > &  k) const

Returns true if the content of k is different from that of *this.

Note that two sequences are equal if and only if they contain the same variables (using Key::operator==) in the same order.

Template Parameters
OtherAllocThe other gum::SequenceImplementation allocator.
Parameters
kThe other gum::SequenceImplementation. Returns true if both gum::SequenceImplementation are not equal.

◆ operator!=() [2/3]

template<typename Key, typename Alloc, bool Gen>
template<typename OtherAlloc >
INLINE bool gum::SequenceImplementation< Key, Alloc, Gen >::operator!= ( const SequenceImplementation< Key, OtherAlloc, Gen > &  k) const

Definition at line 611 of file sequence_tpl.h.

611  {
612  return !operator==(k);
613  }
bool operator==(const SequenceImplementation< Key, OtherAlloc, Gen > &k) const
Returns true if the content of k equals that of *this.
Definition: sequence_tpl.h:596

◆ operator!=() [3/3]

template<typename Key, typename Alloc, bool Gen>
template<typename OtherAlloc >
INLINE bool gum::SequenceImplementation< Key, Alloc, Gen >::operator!= ( const SequenceImplementation< Key, OtherAlloc, true > &  k) const

Definition at line 1011 of file sequence_tpl.h.

1011  {
1012  return !operator==(k);
1013  }
bool operator==(const SequenceImplementation< Key, OtherAlloc, Gen > &k) const
Returns true if the content of k equals that of *this.
Definition: sequence_tpl.h:596

◆ operator<<() [1/2]

template<typename Key, typename Alloc , bool Gen>
INLINE SequenceImplementation< Key, Alloc, Gen > & gum::SequenceImplementation< Key, Alloc, Gen >::operator<< ( const Key &  k)

Insert k at the end of the sequence (synonym for insert).

Parameters
kThe key we wish to insert in the sequence.
Returns
Returns this gum::SequenceImplementation.
Exceptions
DuplicateElementRaised if the sequence contains already k.

Definition at line 438 of file sequence_tpl.h.

438  {
439  insert(k);
440  return *this;
441  }
void insert(const Key &k)
Insert an element at the end of the sequence.
Definition: sequence_tpl.h:408

◆ operator<<() [2/2]

template<typename Key, typename Alloc , bool Gen>
INLINE SequenceImplementation< Key, Alloc, Gen > & gum::SequenceImplementation< Key, Alloc, Gen >::operator<< ( Key &&  k)

Insert k at the end of the sequence (synonym for insert).

Parameters
kThe key we wish to insert in the sequence.
Returns
Returns this gum::SequenceImplementation.
Exceptions
DuplicateElementRaised if the sequence contains already k.

Definition at line 446 of file sequence_tpl.h.

446  {
447  insert(std::move(k));
448  return *this;
449  }
void insert(const Key &k)
Insert an element at the end of the sequence.
Definition: sequence_tpl.h:408

◆ operator=() [1/5]

template<typename Key, typename Alloc, bool Gen>
INLINE SequenceImplementation< Key, Alloc, Gen > & gum::SequenceImplementation< Key, Alloc, Gen >::operator= ( const SequenceImplementation< Key, Alloc, Gen > &  aSeq)
private

Copy operator.

Parameters
aSeqThe sequence to copy.
Returns
Returns a ref to this.

Definition at line 365 of file sequence_tpl.h.

365  {
366  // avoid self assignment
367  if (&aSeq != this) {
368  __copy(aSeq); // performs the __update_end ()
369  }
370 
371  return *this;
372  }
void __copy(const SequenceImplementation< Key, OtherAlloc, Gen > &aSeq)
Clears the current sequence and fill it with copies the element of aSeq.

◆ operator=() [2/5]

template<typename Key, typename Alloc, bool Gen>
template<typename OtherAlloc >
SequenceImplementation< Key, Alloc, Gen >& gum::SequenceImplementation< Key, Alloc, Gen >::operator= ( const SequenceImplementation< Key, OtherAlloc, Gen > &  aSeq)
private

Generalized opy operator.

Template Parameters
OtherAllocThe other gum::SequenceImplementation allocator.
Parameters
aSeqThe sequence to copy.
Returns
Returns a ref to this.

◆ operator=() [3/5]

template<typename Key, typename Alloc, bool Gen>
INLINE SequenceImplementation< Key, Alloc, Gen > & gum::SequenceImplementation< Key, Alloc, Gen >::operator= ( SequenceImplementation< Key, Alloc, Gen > &&  aSeq)
private

Move operator.

Parameters
aSeqThe sequence to move.
Returns
Returns a ref to this.

Definition at line 388 of file sequence_tpl.h.

388  {
389  // avoid self assignment
390  if (&aSeq != this) {
391  __h = std::move(aSeq.__h);
392  __v = std::move(aSeq.__v);
393  __update_end();
394  }
395 
396  return *this;
397  }
HashTable< Key, Idx, Alloc > __h
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:500
void __update_end() noexcept
A method to update the end iterator after changes in the sequence.
Definition: sequence_tpl.h:265
std::vector< Key *, typename Alloc::template rebind< Key *>::other > __v
The set of the elements stored into the sequence.
Definition: sequence.h:503

◆ operator=() [4/5]

template<typename Key, typename Alloc, bool Gen>
template<typename OtherAlloc >
INLINE SequenceImplementation< Key, Alloc, Gen >& gum::SequenceImplementation< Key, Alloc, Gen >::operator= ( const SequenceImplementation< Key, OtherAlloc, Gen > &  aSeq)

Definition at line 379 of file sequence_tpl.h.

379  {
380  __copy(aSeq); // performs the __update_end ()
381  return *this;
382  }
void __copy(const SequenceImplementation< Key, OtherAlloc, Gen > &aSeq)
Clears the current sequence and fill it with copies the element of aSeq.

◆ operator=() [5/5]

template<typename Key, typename Alloc, bool Gen>
template<typename OtherAlloc >
INLINE SequenceImplementation< Key, Alloc, true >& gum::SequenceImplementation< Key, Alloc, Gen >::operator= ( const SequenceImplementation< Key, OtherAlloc, true > &  aSeq)

Definition at line 810 of file sequence_tpl.h.

810  {
811  __copy(aSeq);
812  return *this;
813  }
void __copy(const SequenceImplementation< Key, OtherAlloc, Gen > &aSeq)
Clears the current sequence and fill it with copies the element of aSeq.

◆ operator==() [1/2]

template<typename Key, typename Alloc , bool Gen>
template<typename OtherAlloc >
bool gum::SequenceImplementation< Key, Alloc, Gen >::operator== ( const SequenceImplementation< Key, OtherAlloc, Gen > &  k) const

Returns true if the content of k equals that of *this.

Note that two sequences are equal if and only if they contain the same Keys (using Key::operator==) in the same order.

Template Parameters
OtherAllocThe other gum::SequenceImplementation allocator.
Parameters
kThe other gum::SequenceImplementation. Returns true if both gum::SequenceImplementation are equal.

Definition at line 596 of file sequence_tpl.h.

596  {
597  if (size() != k.size())
598  return false;
599  else {
600  for (Idx i = 0; i < size(); ++i)
601  if (*__v[i] != *(k.__v[i])) return false;
602  }
603 
604  return true;
605  }
Size size() const noexcept
Returns the size of the sequence.
Definition: sequence_tpl.h:38
std::vector< Key *, typename Alloc::template rebind< Key *>::other > __v
The set of the elements stored into the sequence.
Definition: sequence.h:503

◆ operator==() [2/2]

template<typename Key, typename Alloc, bool Gen>
template<typename OtherAlloc >
bool gum::SequenceImplementation< Key, Alloc, Gen >::operator== ( const SequenceImplementation< Key, OtherAlloc, true > &  k) const

Definition at line 996 of file sequence_tpl.h.

996  {
997  if (size() != k.size())
998  return false;
999  else {
1000  for (Idx i = 0; i < size(); ++i)
1001  if (__v[i] != k.__v[i]) return false;
1002  }
1003 
1004  return true;
1005  }
Size size() const noexcept
Returns the size of the sequence.
Definition: sequence_tpl.h:38
std::vector< Key *, typename Alloc::template rebind< Key *>::other > __v
The set of the elements stored into the sequence.
Definition: sequence.h:503

◆ operator>>()

template<typename Key, typename Alloc , bool Gen>
INLINE SequenceImplementation< Key, Alloc, true > & gum::SequenceImplementation< Key, Alloc >::operator>> ( const Key &  k)

Remove k in the sequence (synonym for erase).

If the element cannot be found, the function does nothing. In particular, it throws no exception.

Parameters
kThe key we wish to remove.
Returns
Returns this gum::SequenceImplementation.

Definition at line 493 of file sequence_tpl.h.

493  {
494  erase(k);
495  return *this;
496  }
void erase(const Key &k)
Remove an element from the sequence.
Definition: sequence_tpl.h:453

◆ operator[]()

template<typename Key , typename Alloc >
INLINE const Key & gum::SequenceImplementation< Key, Alloc >::operator[] ( Idx  i) const

Returns the element at position i (synonym for atPos).

Parameters
iThe position of the element to return.
Returns
Returns the element at position i.
Exceptions
OutOfBoundsRaised if the element does not exist.

Definition at line 512 of file sequence_tpl.h.

512  {
513  return atPos(i);
514  }
const Key & atPos(Idx i) const
Returns the object at the pos i.
Definition: sequence_tpl.h:500

◆ pos()

template<typename Key, typename Alloc , bool Gen>
INLINE Idx gum::SequenceImplementation< Key, Alloc >::pos ( const Key &  key) const

Returns the position of the object passed in argument (if it exists).

Parameters
keyThe element for which the positon is returned.
Returns
Returns the position of the object passed in argument.
Exceptions
NotFoundRaised if the element does not exist.

Definition at line 518 of file sequence_tpl.h.

Referenced by gum::prm::SVED< GUM_SCALAR >::__checkElimOrder(), gum::prm::SVE< GUM_SCALAR >::__checkElimOrder(), and gum::learning::genericBNLearner::__learnDAG().

518  {
519  return __h[key];
520  }
HashTable< Key, Idx, Alloc > __h
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:500
+ Here is the caller graph for this function:

◆ rbegin()

template<typename Key , typename Alloc >
INLINE SequenceIterator< Key > gum::SequenceImplementation< Key, Alloc >::rbegin ( ) const

Returns an unsafe rbegin iterator.

Returns
Returns an unsafe rbegin iterator.

Definition at line 671 of file sequence_tpl.h.

671  {
672  SequenceIterator< Key > it{*this};
673  it.__setPos(size() - 1);
674  return it;
675  }
Size size() const noexcept
Returns the size of the sequence.
Definition: sequence_tpl.h:38

◆ rbeginSafe()

template<typename Key , typename Alloc >
INLINE SequenceIteratorSafe< Key > gum::SequenceImplementation< Key, Alloc >::rbeginSafe ( ) const

Returns a safe rbegin iterator.

Returns
Returns a safe rbegin iterator.

Definition at line 641 of file sequence_tpl.h.

641  {
642  SequenceIteratorSafe< Key > it{*this};
643  it.__setPos(size() - 1);
644  return it;
645  }
Size size() const noexcept
Returns the size of the sequence.
Definition: sequence_tpl.h:38
friend class SequenceIteratorSafe< Key >
Friends to speed up access.
Definition: sequence.h:95

◆ rend()

template<typename Key , typename Alloc >
INLINE const SequenceIterator< Key > & gum::SequenceImplementation< Key, Alloc >::rend ( ) const
noexcept

Returns the unsafe rend iterator.

Returns
Returns the unsafe rend iterator.

Definition at line 680 of file sequence_tpl.h.

680  {
681  return __rend_safe;
682  }
SequenceIteratorSafe< Key > __rend_safe
Stores the rend iterator for fast access.
Definition: sequence.h:513

◆ rendSafe()

template<typename Key , typename Alloc >
INLINE const SequenceIteratorSafe< Key > & gum::SequenceImplementation< Key, Alloc >::rendSafe ( ) const
noexcept

Returns the safe rend iterator.

Returns
Returns the safe rend iterator.

Definition at line 650 of file sequence_tpl.h.

650  {
651  return __rend_safe;
652  }
SequenceIteratorSafe< Key > __rend_safe
Stores the rend iterator for fast access.
Definition: sequence.h:513

◆ resize()

template<typename Key , typename Alloc >
INLINE void gum::SequenceImplementation< Key, Alloc >::resize ( Size  new_size)

Modifies the size of the internal structures of the sequence.

This function is provided for optimization issues. When you know you will have to insert elements into the sequence, it may be faster to use this function prior to the additions because it will change once and for all the sizes of all the internal containers. Note that if you provide a size that is smaller than the number of elements of the sequence, the function will not modify anything.

Parameters
new_sizeThe internal structure new size.

Definition at line 686 of file sequence_tpl.h.

Referenced by gum::operator<<(), and gum::SequenceImplementation< gum::prm::PRMClassElement< double > *, std::allocator< gum::prm::PRMClassElement< double > *>, std::is_scalar< gum::prm::PRMClassElement< double > *>::value >::resize().

686  {
687  if (new_size < __h.size()) return;
688 
689  __h.resize(new_size);
690  __v.reserve(new_size);
691  }
void resize(Size new_size)
Changes the number of slots in the &#39;nodes&#39; vector of the hash table.
Size size() const noexcept
Returns the number of elements stored into the hashtable.
HashTable< Key, Idx, Alloc > __h
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:500
std::vector< Key *, typename Alloc::template rebind< Key *>::other > __v
The set of the elements stored into the sequence.
Definition: sequence.h:503
+ Here is the caller graph for this function:

◆ setAtPos() [1/2]

template<typename Key, typename Alloc , bool Gen>
INLINE void gum::SequenceImplementation< Key, Alloc, Gen >::setAtPos ( Idx  i,
const Key &  newKey 
)

Change the value.

Parameters
iThe element's position.
newKeyThe element's new value.
Exceptions
NotFoundRaised if the element does not exist.
DuplicateElementRaised if newKey alreay exists.

Definition at line 525 of file sequence_tpl.h.

Referenced by gum::prm::PRMClass< double >::__inheritClass().

526  {
527  if (i >= __h.size()) { GUM_ERROR(NotFound, "index too large"); }
528 
529  Key& new_key = const_cast< Key& >(__h.insert(newKey, i).first);
530  __h.erase(*(__v[i]));
531  __v[i] = &new_key;
532  }
Size size() const noexcept
Returns the number of elements stored into the hashtable.
void erase(const Key &key)
Removes a given element from the hash table.
HashTable< Key, Idx, Alloc > __h
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:500
std::vector< Key *, typename Alloc::template rebind< Key *>::other > __v
The set of the elements stored into the sequence.
Definition: sequence.h:503
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the caller graph for this function:

◆ setAtPos() [2/2]

template<typename Key, typename Alloc , bool Gen>
INLINE void gum::SequenceImplementation< Key, Alloc, Gen >::setAtPos ( Idx  i,
Key &&  newKey 
)

Change the value.

Parameters
iThe element's position.
newKeyThe element's new value.
Exceptions
NotFoundRaised if the element does not exist.
DuplicateElementRaised if newKey alreay exists.

Definition at line 536 of file sequence_tpl.h.

537  {
538  if (i >= __h.size()) { GUM_ERROR(NotFound, "index too large"); }
539 
540  Key& new_key = const_cast< Key& >(__h.insert(std::move(newKey), i).first);
541  __h.erase(*(__v[i]));
542  __v[i] = &new_key;
543  }
Size size() const noexcept
Returns the number of elements stored into the hashtable.
void erase(const Key &key)
Removes a given element from the hash table.
HashTable< Key, Idx, Alloc > __h
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:500
std::vector< Key *, typename Alloc::template rebind< Key *>::other > __v
The set of the elements stored into the sequence.
Definition: sequence.h:503
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55

◆ size()

template<typename Key , typename Alloc >
INLINE Size gum::SequenceImplementation< Key, Alloc >::size ( ) const
noexcept

◆ swap()

template<typename Key , typename Alloc >
INLINE void gum::SequenceImplementation< Key, Alloc >::swap ( Idx  i,
Idx  j 
)

Swap index.

Parameters
iThe index of the first elt to swap.
jThe index of the other elt to swap.

Definition at line 547 of file sequence_tpl.h.

547  {
548  if (i == j) return;
549 
550  Key& ki = const_cast< Key& >(atPos(i));
551  Key& kj = const_cast< Key& >(atPos(j));
552 
553  __h[ki] = j;
554  __h[kj] = i;
555 
556  __v[i] = &kj;
557  __v[j] = &ki;
558  }
HashTable< Key, Idx, Alloc > __h
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:500
std::vector< Key *, typename Alloc::template rebind< Key *>::other > __v
The set of the elements stored into the sequence.
Definition: sequence.h:503
const Key & atPos(Idx i) const
Returns the object at the pos i.
Definition: sequence_tpl.h:500

◆ toString()

template<typename Key , typename Alloc >
std::string gum::SequenceImplementation< Key, Alloc >::toString ( ) const

Displays the content of the sequence.

Returns
The content of the sequence.

Definition at line 574 of file sequence_tpl.h.

Referenced by gum::operator<<().

574  {
575  std::stringstream stream;
576  stream << "[";
577 
578  if (!__h.empty()) {
579  stream << 0 << ":" << *__v[0];
580 
581  for (Idx i = 1; i < __h.size(); ++i) {
582  stream << " - " << i << ":" << *__v[i];
583  }
584  }
585 
586  stream << "]";
587 
588  std::string res = stream.str();
589  return res;
590  }
Size size() const noexcept
Returns the number of elements stored into the hashtable.
HashTable< Key, Idx, Alloc > __h
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:500
std::vector< Key *, typename Alloc::template rebind< Key *>::other > __v
The set of the elements stored into the sequence.
Definition: sequence.h:503
bool empty() const noexcept
Indicates whether the hash table is empty.
+ Here is the caller graph for this function:

Friends And Related Function Documentation

◆ SequenceImplementation

template<typename Key, typename Alloc, bool Gen>
template<typename K , typename A , bool >
friend class SequenceImplementation
friend

Friends to speed up access.

Definition at line 94 of file sequence.h.

◆ Sequence< Key, Alloc >

template<typename Key, typename Alloc, bool Gen>
friend class Sequence< Key, Alloc >
friend

Friends to speed up access.

Definition at line 96 of file sequence.h.

◆ SequenceIteratorSafe< Key >

template<typename Key, typename Alloc, bool Gen>
friend class SequenceIteratorSafe< Key >
friend

Friends to speed up access.

Definition at line 95 of file sequence.h.

Member Data Documentation

◆ __end_safe

template<typename Key, typename Alloc, bool Gen>
SequenceIteratorSafe< Key > gum::SequenceImplementation< Key, Alloc, Gen >::__end_safe
private

Stores the end iterator for fast access.

Definition at line 510 of file sequence.h.

◆ __h

template<typename Key, typename Alloc, bool Gen>
HashTable< Key, Idx, Alloc > gum::SequenceImplementation< Key, Alloc, Gen >::__h
private

◆ __rend_safe

template<typename Key, typename Alloc, bool Gen>
SequenceIteratorSafe< Key > gum::SequenceImplementation< Key, Alloc, Gen >::__rend_safe
private

Stores the rend iterator for fast access.

Definition at line 513 of file sequence.h.

◆ __v


The documentation for this class was generated from the following files: