aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
gum::SequenceImplementation< Key, Alloc, Gen > Class Template Reference

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

#include <agrum/tools/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 89 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 108 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 110 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 112 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 105 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 103 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 107 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 109 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 111 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 104 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 102 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 106 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 101 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 287 of file sequence_tpl.h.

287  :
288  _h_(size_param), _end_safe_{*this}, _rend_safe_{*this} {
289  GUM_CONSTRUCTOR(SequenceImplementation);
290  _rend_safe_._setAtRend_();
291  _update_end_();
292  }
HashTable< Key, Idx, Alloc > _h_
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:498
friend class SequenceImplementation
Friends to speed up access.
Definition: sequence.h:93
void _update_end_() noexcept
A method to update the end iterator after changes in the sequence.
Definition: sequence_tpl.h:258
SequenceIteratorSafe< Key > _end_safe_
Stores the end iterator for fast access.
Definition: sequence.h:508
SequenceIteratorSafe< Key > _rend_safe_
Stores the rend iterator for fast access.
Definition: sequence.h:511

◆ 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 296 of file sequence_tpl.h.

297  :
298  _end_safe_{*this},
299  _rend_safe_{*this} {
300  GUM_CONSTRUCTOR(SequenceImplementation);
301  _rend_safe_._setAtRend_();
302  for (const auto& elt: list) {
303  insert(elt); // performs the _update_end_ ()
304  }
305  }
friend class SequenceImplementation
Friends to speed up access.
Definition: sequence.h:93
SequenceIteratorSafe< Key > _end_safe_
Stores the end iterator for fast access.
Definition: sequence.h:508
SequenceIteratorSafe< Key > _rend_safe_
Stores the rend iterator for fast access.
Definition: sequence.h:511
void insert(const Key &k)
Insert an element at the end of the sequence.
Definition: sequence_tpl.h:393

◆ 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 309 of file sequence_tpl.h.

310  :
311  _end_safe_{*this},
312  _rend_safe_{*this} {
313  GUM_CONS_CPY(SequenceImplementation);
314  _rend_safe_._setAtRend_();
315  _copy_(aSeq); // performs the _update_end_ ()
316  }
friend class SequenceImplementation
Friends to speed up access.
Definition: sequence.h:93
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:508
SequenceIteratorSafe< Key > _rend_safe_
Stores the rend iterator for fast access.
Definition: sequence.h:511

◆ 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 332 of file sequence_tpl.h.

333  :
334  _h_(std::move(aSeq._h_)),
335  _v_(std::move(aSeq._v_)), _end_safe_{*this}, _rend_safe_{*this} {
336  GUM_CONS_MOV(SequenceImplementation);
337  _rend_safe_._setAtRend_();
338  _update_end_();
339  }
HashTable< Key, Idx, Alloc > _h_
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:498
std::vector< Key *, typename Alloc::template rebind< Key *>::other > _v_
The set of the elements stored into the sequence.
Definition: sequence.h:501
friend class SequenceImplementation
Friends to speed up access.
Definition: sequence.h:93
void _update_end_() noexcept
A method to update the end iterator after changes in the sequence.
Definition: sequence_tpl.h:258
SequenceIteratorSafe< Key > _end_safe_
Stores the end iterator for fast access.
Definition: sequence.h:508
SequenceIteratorSafe< Key > _rend_safe_
Stores the rend iterator for fast access.
Definition: sequence.h:511

◆ ~SequenceImplementation()

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

Class destructor.

Definition at line 343 of file sequence_tpl.h.

343  {
344  GUM_DESTRUCTOR(SequenceImplementation);
345  }
friend class SequenceImplementation
Friends to speed up access.
Definition: sequence.h:93

◆ 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 321 of file sequence_tpl.h.

322  :
323  _end_safe_{*this},
324  _rend_safe_{*this} {
325  GUM_CONS_CPY(SequenceImplementation);
326  _rend_safe_._setAtRend_();
327  _copy_(aSeq); // performs the _update_end_ ()
328  }
friend class SequenceImplementation
Friends to speed up access.
Definition: sequence.h:93
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:508
SequenceIteratorSafe< Key > _rend_safe_
Stores the rend iterator for fast access.
Definition: sequence.h:511

◆ 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 723 of file sequence_tpl.h.

724  :
725  _h_(aSeq._h_),
726  _v_(aSeq._v_), _end_safe_{*this}, _rend_safe_{*this} {
727  GUM_CONS_CPY(SequenceImplementation);
728  _rend_safe_._setAtRend_();
729  _end_safe_._setAtEnd_();
730  }
HashTable< Key, Idx, Alloc > _h_
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:498
std::vector< Key *, typename Alloc::template rebind< Key *>::other > _v_
The set of the elements stored into the sequence.
Definition: sequence.h:501
friend class SequenceImplementation
Friends to speed up access.
Definition: sequence.h:93
SequenceIteratorSafe< Key > _end_safe_
Stores the end iterator for fast access.
Definition: sequence.h:508
SequenceIteratorSafe< Key > _rend_safe_
Stores the rend iterator for fast access.
Definition: sequence.h:511

◆ 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 735 of file sequence_tpl.h.

736  :
737  _h_(aSeq.size() / 2),
738  _end_safe_{*this}, _rend_safe_{*this} {
739  GUM_CONS_CPY(SequenceImplementation);
740  _rend_safe_._setAtRend_();
741  _copy_(aSeq);
742  }
HashTable< Key, Idx, Alloc > _h_
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:498
friend class SequenceImplementation
Friends to speed up access.
Definition: sequence.h:93
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:508
SequenceIteratorSafe< Key > _rend_safe_
Stores the rend iterator for fast access.
Definition: sequence.h:511

◆ 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 746 of file sequence_tpl.h.

747  :
748  _h_(std::move(aSeq._h_)),
749  _v_(std::move(aSeq._v_)), _end_safe_{*this}, _rend_safe_{*this} {
750  GUM_CONS_MOV(SequenceImplementation);
751  _rend_safe_._setAtRend_();
752  _end_safe_._setAtEnd_();
753  }
HashTable< Key, Idx, Alloc > _h_
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:498
std::vector< Key *, typename Alloc::template rebind< Key *>::other > _v_
The set of the elements stored into the sequence.
Definition: sequence.h:501
friend class SequenceImplementation
Friends to speed up access.
Definition: sequence.h:93
SequenceIteratorSafe< Key > _end_safe_
Stores the end iterator for fast access.
Definition: sequence.h:508
SequenceIteratorSafe< Key > _rend_safe_
Stores the rend iterator for fast access.
Definition: sequence.h:511

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 273 of file sequence_tpl.h.

274  {
275  clear();
276 
277  for (Size i = 0; i < aSeq.size(); ++i) {
278  Key& new_key = const_cast< Key& >(_h_.insert(*(aSeq._v_[i]), i).first);
279  _v_.push_back(&new_key);
280  }
281 
282  _update_end_();
283  }
HashTable< Key, Idx, Alloc > _h_
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:498
std::vector< Key *, typename Alloc::template rebind< Key *>::other > _v_
The set of the elements stored into the sequence.
Definition: sequence.h:501
void clear()
Clear the sequence.
Definition: sequence_tpl.h:264
void _update_end_() noexcept
A method to update the end iterator after changes in the sequence.
Definition: sequence_tpl.h:258
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
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 687 of file sequence_tpl.h.

688  {
689  clear();
690 
691  for (Size i = 0; i < aSeq.size(); ++i) {
692  _h_.insert(aSeq._v_[i], i);
693  _v_.push_back(aSeq._v_[i]);
694  }
695 
696  _update_end_();
697  }
HashTable< Key, Idx, Alloc > _h_
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:498
std::vector< Key *, typename Alloc::template rebind< Key *>::other > _v_
The set of the elements stored into the sequence.
Definition: sequence.h:501
void clear()
Clear the sequence.
Definition: sequence_tpl.h:264
void _update_end_() noexcept
A method to update the end iterator after changes in the sequence.
Definition: sequence_tpl.h:258
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
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 258 of file sequence_tpl.h.

258  {
259  _end_safe_._setAtEnd_();
260  }
SequenceIteratorSafe< Key > _end_safe_
Stores the end iterator for fast access.
Definition: sequence.h:508

◆ 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 483 of file sequence_tpl.h.

483  {
484  if (i >= _h_.size()) {
485  GUM_ERROR(OutOfBounds, "index " << i << " for a sequence of size" << _h_.size())
486  }
487 
488  return *(_v_[i]);
489  }
HashTable< Key, Idx, Alloc > _h_
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:498
std::vector< Key *, typename Alloc::template rebind< Key *>::other > _v_
The set of the elements stored into the sequence.
Definition: sequence.h:501
Size size() const noexcept
Returns the number of elements stored into the hashtable.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ 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 546 of file sequence_tpl.h.

546  {
547  return atPos(size() - 1);
548  }
Size size() const noexcept
Returns the size of the sequence.
Definition: sequence_tpl.h:37
const Key & atPos(Idx i) const
Returns the object at the pos i.
Definition: sequence_tpl.h:483

◆ 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 631 of file sequence_tpl.h.

631  {
632  return SequenceIterator< Key >{*this};
633  }

◆ 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 603 of file sequence_tpl.h.

603  {
604  return SequenceIteratorSafe< Key >{*this};
605  }
friend class SequenceIteratorSafe< Key >
Friends to speed up access.
Definition: sequence.h:94

◆ clear()

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

Clear the sequence.

Definition at line 264 of file sequence_tpl.h.

264  {
265  _h_.clear();
266  _v_.clear();
267  _update_end_();
268  }
HashTable< Key, Idx, Alloc > _h_
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:498
std::vector< Key *, typename Alloc::template rebind< Key *>::other > _v_
The set of the elements stored into the sequence.
Definition: sequence.h:501
void _update_end_() noexcept
A method to update the end iterator after changes in the sequence.
Definition: sequence_tpl.h:258
void clear()
Removes all the elements in the hash table.

◆ 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 412 of file sequence_tpl.h.

412  {
413  Key key(std::forward< Args >(args)...);
414  Key& new_key = const_cast< Key& >(_h_.insert(std::move(key), _h_.size()).first);
415  _v_.push_back(&new_key);
416  _update_end_();
417  }
HashTable< Key, Idx, Alloc > _h_
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:498
std::vector< Key *, typename Alloc::template rebind< Key *>::other > _v_
The set of the elements stored into the sequence.
Definition: sequence.h:501
Size size() const noexcept
Returns the number of elements stored into the hashtable.
void _update_end_() noexcept
A method to update the end iterator after changes in the sequence.
Definition: sequence_tpl.h:258
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 43 of file sequence_tpl.h.

43  {
44  return _h_.empty();
45  }
HashTable< Key, Idx, Alloc > _h_
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:498
bool empty() const noexcept
Indicates whether the hash table is empty.

◆ 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 638 of file sequence_tpl.h.

638  {
639  return _end_safe_;
640  }
SequenceIteratorSafe< Key > _end_safe_
Stores the end iterator for fast access.
Definition: sequence.h:508

◆ 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 610 of file sequence_tpl.h.

610  {
611  return _end_safe_;
612  }
SequenceIteratorSafe< Key > _end_safe_
Stores the end iterator for fast access.
Definition: sequence.h:508

◆ 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 437 of file sequence_tpl.h.

437  {
438  // get the position of the element to remove
439  Idx pos;
440 
441  try {
442  pos = _h_[k];
443  } catch (NotFound&) { return; }
444 
445  // erase the element
446  _v_.erase(_v_.begin() + pos);
447  for (Idx i = pos, nb_elts = _h_.size() - 1; i < nb_elts; ++i) {
448  --_h_[*(_v_[i])];
449  }
450  _h_.erase(k);
451 
452  _update_end_();
453  }
HashTable< Key, Idx, Alloc > _h_
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:498
Idx pos(const Key &key) const
Returns the position of the object passed in argument (if it exists).
Definition: sequence_tpl.h:499
std::vector< Key *, typename Alloc::template rebind< Key *>::other > _v_
The set of the elements stored into the sequence.
Definition: sequence.h:501
Size size() const noexcept
Returns the number of elements stored into the hashtable.
void _update_end_() noexcept
A method to update the end iterator after changes in the sequence.
Definition: sequence_tpl.h:258
void erase(const Key &key)
Removes a given element from the hash table.

◆ 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 457 of file sequence_tpl.h.

457  {
458  if (iter.pos() >= size()) return;
459 
460  // erase the element
461  Idx pos = iter.pos();
462  Key* key = _v_[pos];
463  _v_.erase(_v_.begin() + pos);
464 
465  for (Idx i = pos, nb_elts = _h_.size() - 1; i < nb_elts; ++i) {
466  --_h_[*(_v_[i])];
467  }
468  _h_.erase(*key);
469 
470  _update_end_();
471  }
HashTable< Key, Idx, Alloc > _h_
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:498
Idx pos(const Key &key) const
Returns the position of the object passed in argument (if it exists).
Definition: sequence_tpl.h:499
std::vector< Key *, typename Alloc::template rebind< Key *>::other > _v_
The set of the elements stored into the sequence.
Definition: sequence.h:501
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:37
void _update_end_() noexcept
A method to update the end iterator after changes in the sequence.
Definition: sequence_tpl.h:258
void erase(const Key &key)
Removes a given element from the hash table.

◆ 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 387 of file sequence_tpl.h.

387  {
388  return _h_.exists(k);
389  }
HashTable< Key, Idx, Alloc > _h_
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:498
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.

◆ 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 540 of file sequence_tpl.h.

540  {
541  return atPos(0);
542  }
const Key & atPos(Idx i) const
Returns the object at the pos i.
Definition: sequence_tpl.h:483

◆ 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 393 of file sequence_tpl.h.

393  {
394  // k will be added at the end. Insert the new key into the hashtable
395  Key& new_key = const_cast< Key& >(_h_.insert(k, _h_.size()).first);
396  _v_.push_back(&new_key);
397  _update_end_();
398  }
HashTable< Key, Idx, Alloc > _h_
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:498
std::vector< Key *, typename Alloc::template rebind< Key *>::other > _v_
The set of the elements stored into the sequence.
Definition: sequence.h:501
Size size() const noexcept
Returns the number of elements stored into the hashtable.
void _update_end_() noexcept
A method to update the end iterator after changes in the sequence.
Definition: sequence_tpl.h:258
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.

◆ 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 402 of file sequence_tpl.h.

402  {
403  // k will be added at the end. Insert the new key into the hashtable
404  Key& new_key = const_cast< Key& >(_h_.insert(std::move(k), _h_.size()).first);
405  _v_.push_back(&new_key);
406  _update_end_();
407  }
HashTable< Key, Idx, Alloc > _h_
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:498
std::vector< Key *, typename Alloc::template rebind< Key *>::other > _v_
The set of the elements stored into the sequence.
Definition: sequence.h:501
Size size() const noexcept
Returns the number of elements stored into the hashtable.
void _update_end_() noexcept
A method to update the end iterator after changes in the sequence.
Definition: sequence_tpl.h:258
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 588 of file sequence_tpl.h.

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

◆ 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 971 of file sequence_tpl.h.

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

◆ 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 422 of file sequence_tpl.h.

422  {
423  insert(k);
424  return *this;
425  }
void insert(const Key &k)
Insert an element at the end of the sequence.
Definition: sequence_tpl.h:393

◆ 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 430 of file sequence_tpl.h.

430  {
431  insert(std::move(k));
432  return *this;
433  }
void insert(const Key &k)
Insert an element at the end of the sequence.
Definition: sequence_tpl.h:393

◆ 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 350 of file sequence_tpl.h.

351  {
352  // avoid self assignment
353  if (&aSeq != this) {
354  _copy_(aSeq); // performs the _update_end_ ()
355  }
356 
357  return *this;
358  }
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 373 of file sequence_tpl.h.

374  {
375  // avoid self assignment
376  if (&aSeq != this) {
377  _h_ = std::move(aSeq._h_);
378  _v_ = std::move(aSeq._v_);
379  _update_end_();
380  }
381 
382  return *this;
383  }
HashTable< Key, Idx, Alloc > _h_
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:498
std::vector< Key *, typename Alloc::template rebind< Key *>::other > _v_
The set of the elements stored into the sequence.
Definition: sequence.h:501
void _update_end_() noexcept
A method to update the end iterator after changes in the sequence.
Definition: sequence_tpl.h:258

◆ 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 364 of file sequence_tpl.h.

365  {
366  _copy_(aSeq); // performs the _update_end_ ()
367  return *this;
368  }
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 776 of file sequence_tpl.h.

777  {
778  _copy_(aSeq);
779  return *this;
780  }
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 573 of file sequence_tpl.h.

574  {
575  if (size() != k.size())
576  return false;
577  else {
578  for (Idx i = 0; i < size(); ++i)
579  if (*_v_[i] != *(k._v_[i])) return false;
580  }
581 
582  return true;
583  }
std::vector< Key *, typename Alloc::template rebind< Key *>::other > _v_
The set of the elements stored into the sequence.
Definition: sequence.h:501
Size size() const noexcept
Returns the size of the sequence.
Definition: sequence_tpl.h:37

◆ 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 956 of file sequence_tpl.h.

957  {
958  if (size() != k.size())
959  return false;
960  else {
961  for (Idx i = 0; i < size(); ++i)
962  if (_v_[i] != k._v_[i]) return false;
963  }
964 
965  return true;
966  }
std::vector< Key *, typename Alloc::template rebind< Key *>::other > _v_
The set of the elements stored into the sequence.
Definition: sequence.h:501
Size size() const noexcept
Returns the size of the sequence.
Definition: sequence_tpl.h:37

◆ 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 476 of file sequence_tpl.h.

476  {
477  erase(k);
478  return *this;
479  }
void erase(const Key &k)
Remove an element from the sequence.
Definition: sequence_tpl.h:437

◆ 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 493 of file sequence_tpl.h.

493  {
494  return atPos(i);
495  }
const Key & atPos(Idx i) const
Returns the object at the pos i.
Definition: sequence_tpl.h:483

◆ 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 499 of file sequence_tpl.h.

499  {
500  return _h_[key];
501  }
HashTable< Key, Idx, Alloc > _h_
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:498

◆ 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 644 of file sequence_tpl.h.

644  {
645  SequenceIterator< Key > it{*this};
646  it._setPos_(size() - 1);
647  return it;
648  }
Size size() const noexcept
Returns the size of the sequence.
Definition: sequence_tpl.h:37

◆ 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 616 of file sequence_tpl.h.

616  {
617  SequenceIteratorSafe< Key > it{*this};
618  it._setPos_(size() - 1);
619  return it;
620  }
Size size() const noexcept
Returns the size of the sequence.
Definition: sequence_tpl.h:37
friend class SequenceIteratorSafe< Key >
Friends to speed up access.
Definition: sequence.h:94

◆ 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 653 of file sequence_tpl.h.

653  {
654  return _rend_safe_;
655  }
SequenceIteratorSafe< Key > _rend_safe_
Stores the rend iterator for fast access.
Definition: sequence.h:511

◆ 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 625 of file sequence_tpl.h.

625  {
626  return _rend_safe_;
627  }
SequenceIteratorSafe< Key > _rend_safe_
Stores the rend iterator for fast access.
Definition: sequence.h:511

◆ 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 659 of file sequence_tpl.h.

659  {
660  if (new_size < _h_.size()) return;
661 
662  _h_.resize(new_size);
663  _v_.reserve(new_size);
664  }
void resize(Size new_size)
Changes the number of slots in the &#39;nodes&#39; vector of the hash table.
HashTable< Key, Idx, Alloc > _h_
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:498
std::vector< Key *, typename Alloc::template rebind< Key *>::other > _v_
The set of the elements stored into the sequence.
Definition: sequence.h:501
Size size() const noexcept
Returns the number of elements stored into the hashtable.

◆ 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 505 of file sequence_tpl.h.

505  {
506  if (i >= _h_.size()) { GUM_ERROR(NotFound, "index too large") }
507 
508  Key& new_key = const_cast< Key& >(_h_.insert(newKey, i).first);
509  _h_.erase(*(_v_[i]));
510  _v_[i] = &new_key;
511  }
HashTable< Key, Idx, Alloc > _h_
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:498
std::vector< Key *, typename Alloc::template rebind< Key *>::other > _v_
The set of the elements stored into the sequence.
Definition: sequence.h:501
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.
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:51

◆ 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 515 of file sequence_tpl.h.

515  {
516  if (i >= _h_.size()) { GUM_ERROR(NotFound, "index too large") }
517 
518  Key& new_key = const_cast< Key& >(_h_.insert(std::move(newKey), i).first);
519  _h_.erase(*(_v_[i]));
520  _v_[i] = &new_key;
521  }
HashTable< Key, Idx, Alloc > _h_
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:498
std::vector< Key *, typename Alloc::template rebind< Key *>::other > _v_
The set of the elements stored into the sequence.
Definition: sequence.h:501
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.
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:51

◆ size()

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

Returns the size of the sequence.

Returns
Returns the size of the sequence.

Definition at line 37 of file sequence_tpl.h.

37  {
38  return _h_.size();
39  }
HashTable< Key, Idx, Alloc > _h_
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:498
Size size() const noexcept
Returns the number of elements stored into the hashtable.

◆ 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 525 of file sequence_tpl.h.

525  {
526  if (i == j) return;
527 
528  Key& ki = const_cast< Key& >(atPos(i));
529  Key& kj = const_cast< Key& >(atPos(j));
530 
531  _h_[ki] = j;
532  _h_[kj] = i;
533 
534  _v_[i] = &kj;
535  _v_[j] = &ki;
536  }
HashTable< Key, Idx, Alloc > _h_
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:498
std::vector< Key *, typename Alloc::template rebind< Key *>::other > _v_
The set of the elements stored into the sequence.
Definition: sequence.h:501
const Key & atPos(Idx i) const
Returns the object at the pos i.
Definition: sequence_tpl.h:483

◆ 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 552 of file sequence_tpl.h.

552  {
553  std::stringstream stream;
554  stream << "[";
555 
556  if (!_h_.empty()) {
557  stream << 0 << ":" << *_v_[0];
558 
559  for (Idx i = 1; i < _h_.size(); ++i) {
560  stream << " - " << i << ":" << *_v_[i];
561  }
562  }
563 
564  stream << "]";
565 
566  std::string res = stream.str();
567  return res;
568  }
HashTable< Key, Idx, Alloc > _h_
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:498
std::vector< Key *, typename Alloc::template rebind< Key *>::other > _v_
The set of the elements stored into the sequence.
Definition: sequence.h:501
Size size() const noexcept
Returns the number of elements stored into the hashtable.
bool empty() const noexcept
Indicates whether the hash table is empty.

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 93 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 95 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 94 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 508 of file sequence.h.

◆ _h_

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

Keep track of the position of the element in v (for fast retrieval).

Definition at line 498 of file sequence.h.

◆ _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 511 of file sequence.h.

◆ _v_

template<typename Key, typename Alloc, bool Gen>
std::vector< Key*, typename Alloc::template rebind< Key* >::other > gum::SequenceImplementation< Key, Alloc, Gen >::_v_
private

The set of the elements stored into the sequence.

Definition at line 501 of file sequence.h.


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