aGrUM  0.20.2
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 295 of file sequence_tpl.h.

296  :
297  h__(size_param),
298  end_safe__{*this}, rend_safe__{*this} {
299  // for debugging purposes
300  GUM_CONSTRUCTOR(SequenceImplementation);
301  rend_safe__.setAtRend__();
302  update_end__();
303  }
SequenceIteratorSafe< Key > end_safe__
Stores the end iterator for fast access.
Definition: sequence.h:509
friend class SequenceImplementation
Friends to speed up access.
Definition: sequence.h:93
HashTable< Key, Idx, Alloc > h__
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:499
void update_end__() noexcept
A method to update the end iterator after changes in the sequence.
Definition: sequence_tpl.h:266
SequenceIteratorSafe< Key > rend_safe__
Stores the rend iterator for fast access.
Definition: sequence.h:512

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

308  :
309  end_safe__{*this},
310  rend_safe__{*this} {
311  GUM_CONSTRUCTOR(SequenceImplementation);
312  rend_safe__.setAtRend__();
313  for (const auto& elt: list) {
314  insert(elt); // performs the update_end__ ()
315  }
316  }
SequenceIteratorSafe< Key > end_safe__
Stores the end iterator for fast access.
Definition: sequence.h:509
friend class SequenceImplementation
Friends to speed up access.
Definition: sequence.h:93
SequenceIteratorSafe< Key > rend_safe__
Stores the rend iterator for fast access.
Definition: sequence.h:512
void insert(const Key &k)
Insert an element at the end of the sequence.
Definition: sequence_tpl.h:409

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

321  :
322  end_safe__{*this},
323  rend_safe__{*this} {
324  // for debugging purposes
325  GUM_CONS_CPY(SequenceImplementation);
326  rend_safe__.setAtRend__();
327  copy__(aSeq); // performs the update_end__ ()
328  }
SequenceIteratorSafe< Key > end_safe__
Stores the end iterator for fast access.
Definition: sequence.h:509
void copy__(const SequenceImplementation< Key, OtherAlloc, Gen > &aSeq)
Clears the current sequence and fill it with copies the element of aSeq.
friend class SequenceImplementation
Friends to speed up access.
Definition: sequence.h:93
SequenceIteratorSafe< Key > rend_safe__
Stores the rend iterator for fast access.
Definition: sequence.h:512

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

346  :
347  h__(std::move(aSeq.h__)),
348  v__(std::move(aSeq.v__)), end_safe__{*this}, rend_safe__{*this} {
349  // for debugging purposes
350  GUM_CONS_MOV(SequenceImplementation);
351  rend_safe__.setAtRend__();
352  update_end__();
353  }
SequenceIteratorSafe< Key > end_safe__
Stores the end iterator for fast access.
Definition: sequence.h:509
friend class SequenceImplementation
Friends to speed up access.
Definition: sequence.h:93
std::vector< Key *, typename Alloc::template rebind< Key *>::other > v__
The set of the elements stored into the sequence.
Definition: sequence.h:502
HashTable< Key, Idx, Alloc > h__
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:499
void update_end__() noexcept
A method to update the end iterator after changes in the sequence.
Definition: sequence_tpl.h:266
SequenceIteratorSafe< Key > rend_safe__
Stores the rend iterator for fast access.
Definition: sequence.h:512

◆ ~SequenceImplementation()

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

Class destructor.

Definition at line 358 of file sequence_tpl.h.

358  {
359  GUM_DESTRUCTOR(SequenceImplementation);
360  }
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 333 of file sequence_tpl.h.

334  :
335  end_safe__{*this},
336  rend_safe__{*this} {
337  // for debugging purposes
338  GUM_CONS_CPY(SequenceImplementation);
339  rend_safe__.setAtRend__();
340  copy__(aSeq); // performs the update_end__ ()
341  }
SequenceIteratorSafe< Key > end_safe__
Stores the end iterator for fast access.
Definition: sequence.h:509
void copy__(const SequenceImplementation< Key, OtherAlloc, Gen > &aSeq)
Clears the current sequence and fill it with copies the element of aSeq.
friend class SequenceImplementation
Friends to speed up access.
Definition: sequence.h:93
SequenceIteratorSafe< Key > rend_safe__
Stores the rend iterator for fast access.
Definition: sequence.h:512

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

755  :
756  h__(aSeq.h__),
757  v__(aSeq.v__), end_safe__{*this}, rend_safe__{*this} {
758  // for debugging purposes
759  GUM_CONS_CPY(SequenceImplementation);
760  rend_safe__.setAtRend__();
761  end_safe__.setAtEnd__();
762  }
SequenceIteratorSafe< Key > end_safe__
Stores the end iterator for fast access.
Definition: sequence.h:509
friend class SequenceImplementation
Friends to speed up access.
Definition: sequence.h:93
std::vector< Key *, typename Alloc::template rebind< Key *>::other > v__
The set of the elements stored into the sequence.
Definition: sequence.h:502
HashTable< Key, Idx, Alloc > h__
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:499
SequenceIteratorSafe< Key > rend_safe__
Stores the rend iterator for fast access.
Definition: sequence.h:512

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

768  :
769  h__(aSeq.size() / 2),
770  end_safe__{*this}, rend_safe__{*this} {
771  // for debugging purposes
772  GUM_CONS_CPY(SequenceImplementation);
773  rend_safe__.setAtRend__();
774  copy__(aSeq);
775  }
SequenceIteratorSafe< Key > end_safe__
Stores the end iterator for fast access.
Definition: sequence.h:509
void copy__(const SequenceImplementation< Key, OtherAlloc, Gen > &aSeq)
Clears the current sequence and fill it with copies the element of aSeq.
friend class SequenceImplementation
Friends to speed up access.
Definition: sequence.h:93
HashTable< Key, Idx, Alloc > h__
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:499
SequenceIteratorSafe< Key > rend_safe__
Stores the rend iterator for fast access.
Definition: sequence.h:512

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

780  :
781  h__(std::move(aSeq.h__)),
782  v__(std::move(aSeq.v__)), end_safe__{*this}, rend_safe__{*this} {
783  // for debugging purposes
784  GUM_CONS_MOV(SequenceImplementation);
785  rend_safe__.setAtRend__();
786  end_safe__.setAtEnd__();
787  }
SequenceIteratorSafe< Key > end_safe__
Stores the end iterator for fast access.
Definition: sequence.h:509
friend class SequenceImplementation
Friends to speed up access.
Definition: sequence.h:93
std::vector< Key *, typename Alloc::template rebind< Key *>::other > v__
The set of the elements stored into the sequence.
Definition: sequence.h:502
HashTable< Key, Idx, Alloc > h__
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:499
SequenceIteratorSafe< Key > rend_safe__
Stores the rend iterator for fast access.
Definition: sequence.h:512

Member Function Documentation

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

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

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

569  {
570  return atPos(size() - 1);
571  }
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:501

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

658  {
659  return SequenceIterator< Key >{*this};
660  }

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

628  {
629  return SequenceIteratorSafe< Key >{*this};
630  }
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 272 of file sequence_tpl.h.

272  {
273  h__.clear();
274  v__.clear();
275  update_end__();
276  }
std::vector< Key *, typename Alloc::template rebind< Key *>::other > v__
The set of the elements stored into the sequence.
Definition: sequence.h:502
HashTable< Key, Idx, Alloc > h__
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:499
void clear()
Removes all the elements in the hash table.
void update_end__() noexcept
A method to update the end iterator after changes in the sequence.
Definition: sequence_tpl.h:266

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

282  {
283  clear();
284 
285  for (Size i = 0; i < aSeq.size(); ++i) {
286  Key& new_key = const_cast< Key& >(h__.insert(*(aSeq.v__[i]), i).first);
287  v__.push_back(&new_key);
288  }
289 
290  update_end__();
291  }
void clear()
Clear the sequence.
Definition: sequence_tpl.h:272
std::vector< Key *, typename Alloc::template rebind< Key *>::other > v__
The set of the elements stored into the sequence.
Definition: sequence.h:502
HashTable< Key, Idx, Alloc > h__
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:499
void update_end__() noexcept
A method to update the end iterator after changes in the sequence.
Definition: sequence_tpl.h:266
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 715 of file sequence_tpl.h.

716  {
717  clear();
718 
719  for (Size i = 0; i < aSeq.size(); ++i) {
720  h__.insert(aSeq.v__[i], i);
721  v__.push_back(aSeq.v__[i]);
722  }
723 
724  update_end__();
725  }
void clear()
Clear the sequence.
Definition: sequence_tpl.h:272
std::vector< Key *, typename Alloc::template rebind< Key *>::other > v__
The set of the elements stored into the sequence.
Definition: sequence.h:502
HashTable< Key, Idx, Alloc > h__
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:499
void update_end__() noexcept
A method to update the end iterator after changes in the sequence.
Definition: sequence_tpl.h:266
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.

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

428  {
429  Key key(std::forward< Args >(args)...);
430  Key& new_key
431  = const_cast< Key& >(h__.insert(std::move(key), h__.size()).first);
432  v__.push_back(&new_key);
433  update_end__();
434  }
Size size() const noexcept
Returns the number of elements stored into the hashtable.
std::vector< Key *, typename Alloc::template rebind< Key *>::other > v__
The set of the elements stored into the sequence.
Definition: sequence.h:502
HashTable< Key, Idx, Alloc > h__
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:499
void update_end__() noexcept
A method to update the end iterator after changes in the sequence.
Definition: sequence_tpl.h:266
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:499
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 665 of file sequence_tpl.h.

665  {
666  return end_safe__;
667  }
SequenceIteratorSafe< Key > end_safe__
Stores the end iterator for fast access.
Definition: sequence.h:509

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

635  {
636  return end_safe__;
637  }
SequenceIteratorSafe< Key > end_safe__
Stores the end iterator for fast access.
Definition: sequence.h:509

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

454  {
455  // get the position of the element to remove
456  Idx pos;
457 
458  try {
459  pos = h__[k];
460  } catch (NotFound&) { return; }
461 
462  // erase the element
463  v__.erase(v__.begin() + pos);
464  for (Idx i = pos, nb_elts = h__.size() - 1; i < nb_elts; ++i) {
465  --h__[*(v__[i])];
466  }
467  h__.erase(k);
468 
469  update_end__();
470  }
Idx pos(const Key &key) const
Returns the position of the object passed in argument (if it exists).
Definition: sequence_tpl.h:519
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.
std::vector< Key *, typename Alloc::template rebind< Key *>::other > v__
The set of the elements stored into the sequence.
Definition: sequence.h:502
HashTable< Key, Idx, Alloc > h__
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:499
void update_end__() noexcept
A method to update the end iterator after changes in the sequence.
Definition: sequence_tpl.h:266

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

475  {
476  if (iter.pos() >= size()) return;
477 
478  // erase the element
479  Idx pos = iter.pos();
480  Key* key = v__[pos];
481  v__.erase(v__.begin() + pos);
482 
483  for (Idx i = pos, nb_elts = h__.size() - 1; i < nb_elts; ++i) {
484  --h__[*(v__[i])];
485  }
486  h__.erase(*key);
487 
488  update_end__();
489  }
Idx pos(const Key &key) const
Returns the position of the object passed in argument (if it exists).
Definition: sequence_tpl.h:519
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 erase(const Key &key)
Removes a given element from 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:502
HashTable< Key, Idx, Alloc > h__
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:499
void update_end__() noexcept
A method to update the end iterator after changes in the sequence.
Definition: sequence_tpl.h:266

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

403  {
404  return h__.exists(k);
405  }
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:499

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

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

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

409  {
410  // k will be added at the end. Insert the new key into the hashtable
411  Key& new_key = const_cast< Key& >(h__.insert(k, h__.size()).first);
412  v__.push_back(&new_key);
413  update_end__();
414  }
Size size() const noexcept
Returns the number of elements stored into the hashtable.
std::vector< Key *, typename Alloc::template rebind< Key *>::other > v__
The set of the elements stored into the sequence.
Definition: sequence.h:502
HashTable< Key, Idx, Alloc > h__
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:499
void update_end__() noexcept
A method to update the end iterator after changes in the sequence.
Definition: sequence_tpl.h:266
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 418 of file sequence_tpl.h.

418  {
419  // k will be added at the end. Insert the new key into the hashtable
420  Key& new_key = const_cast< Key& >(h__.insert(std::move(k), h__.size()).first);
421  v__.push_back(&new_key);
422  update_end__();
423  }
Size size() const noexcept
Returns the number of elements stored into the hashtable.
std::vector< Key *, typename Alloc::template rebind< Key *>::other > v__
The set of the elements stored into the sequence.
Definition: sequence.h:502
HashTable< Key, Idx, Alloc > h__
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:499
void update_end__() noexcept
A method to update the end iterator after changes in the sequence.
Definition: sequence_tpl.h:266
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.

◆ 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.

612  {
613  return !operator==(k);
614  }
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.

1012  {
1013  return !operator==(k);
1014  }
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 439 of file sequence_tpl.h.

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

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

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

◆ 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.

366  {
367  // avoid self assignment
368  if (&aSeq != this) {
369  copy__(aSeq); // performs the update_end__ ()
370  }
371 
372  return *this;
373  }
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.

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

◆ 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.

380  {
381  copy__(aSeq); // performs the update_end__ ()
382  return *this;
383  }
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.

811  {
812  copy__(aSeq);
813  return *this;
814  }
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.

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

◆ 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.

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

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

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

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

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

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

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

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

672  {
673  SequenceIterator< Key > it{*this};
674  it.setPos__(size() - 1);
675  return it;
676  }
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 642 of file sequence_tpl.h.

642  {
643  SequenceIteratorSafe< Key > it{*this};
644  it.setPos__(size() - 1);
645  return it;
646  }
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 681 of file sequence_tpl.h.

681  {
682  return rend_safe__;
683  }
SequenceIteratorSafe< Key > rend_safe__
Stores the rend iterator for fast access.
Definition: sequence.h:512

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

651  {
652  return rend_safe__;
653  }
SequenceIteratorSafe< Key > rend_safe__
Stores the rend iterator for fast access.
Definition: sequence.h:512

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

687  {
688  if (new_size < h__.size()) return;
689 
690  h__.resize(new_size);
691  v__.reserve(new_size);
692  }
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.
std::vector< Key *, typename Alloc::template rebind< Key *>::other > v__
The set of the elements stored into the sequence.
Definition: sequence.h:502
HashTable< Key, Idx, Alloc > h__
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:499

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

527  {
528  if (i >= h__.size()) { GUM_ERROR(NotFound, "index too large"); }
529 
530  Key& new_key = const_cast< Key& >(h__.insert(newKey, i).first);
531  h__.erase(*(v__[i]));
532  v__[i] = &new_key;
533  }
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.
std::vector< Key *, typename Alloc::template rebind< Key *>::other > v__
The set of the elements stored into the sequence.
Definition: sequence.h:502
HashTable< Key, Idx, Alloc > h__
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:499
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:54

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

538  {
539  if (i >= h__.size()) { GUM_ERROR(NotFound, "index too large"); }
540 
541  Key& new_key = const_cast< Key& >(h__.insert(std::move(newKey), i).first);
542  h__.erase(*(v__[i]));
543  v__[i] = &new_key;
544  }
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.
std::vector< Key *, typename Alloc::template rebind< Key *>::other > v__
The set of the elements stored into the sequence.
Definition: sequence.h:502
HashTable< Key, Idx, Alloc > h__
Keep track of the position of the element in v (for fast retrieval).
Definition: sequence.h:499
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:54

◆ 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  }
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:499

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

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

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

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

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

266  {
267  end_safe__.setAtEnd__();
268  }
SequenceIteratorSafe< Key > end_safe__
Stores the end iterator for fast access.
Definition: sequence.h:509

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 509 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 499 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 512 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 502 of file sequence.h.


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