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

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

#include <agrum/base/core/sequence.h>

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

Public Types

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

Public Member Functions

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

Private Member Functions

void _update_end_ () noexcept
 A method to update the end iterator after changes in the sequence.
void _copy_ (const SequenceImplementation< Key, Gen > &aSeq)
 Clears the current sequence and fill it with copies the element of aSeq.
void _insert_ (HashTableBucket< Key, Idx > &&bucket)
 Insert an element at the end of the sequence.
Constructors
 SequenceImplementation (Size size_param=HashTableConst::default_size)
 Default constructor.
 SequenceImplementation (std::initializer_list< Key > list)
 Initializer list constructor.
 SequenceImplementation (const SequenceImplementation< Key, Gen > &aSeq)
 Copy constructor.
 SequenceImplementation (SequenceImplementation< Key, Gen > &&aSeq)
 Move constructor.
Private Operators
SequenceImplementation< Key, Gen > & operator= (const SequenceImplementation< Key, Gen > &aSeq)
 Copy operator.
SequenceImplementation< Key, Gen > & operator= (SequenceImplementation< Key, Gen > &&aSeq)
 Move operator.

Private Attributes

HashTable< Key, Idx_h_
 Keep track of the position of the element in v (for fast retrieval).
std::vector< Key * > _v_
 The set of the elements stored into the sequence.
SequenceIteratorSafe< Key > _end_safe_
 Stores the end iterator for fast access.
SequenceIteratorSafe< Key > _rend_safe_
 Stores the rend iterator for fast access.

Friends

class SequenceIteratorSafe< Key >
 Friends to speed up access.
class Sequence< Key >
 Friends to speed up access.

Detailed Description

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

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

A SequenceImplementation<Key,bool Gen> is a specialized version of of a Sequence<Key>. 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.
GenUsed for meta-programation.

Definition at line 109 of file sequence.h.

Member Typedef Documentation

◆ const_iterator

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

Types for STL compliance.

Definition at line 127 of file sequence.h.

◆ const_iterator_safe

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

Types for STL compliance.

Definition at line 129 of file sequence.h.

◆ const_pointer

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

Types for STL compliance.

Definition at line 123 of file sequence.h.

◆ const_reference

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

Types for STL compliance.

Definition at line 121 of file sequence.h.

◆ difference_type

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

Types for STL compliance.

Definition at line 125 of file sequence.h.

◆ iterator

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

Types for STL compliance.

Definition at line 126 of file sequence.h.

◆ iterator_safe

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

Types for STL compliance.

Definition at line 128 of file sequence.h.

◆ pointer

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

Types for STL compliance.

Definition at line 122 of file sequence.h.

◆ reference

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

Types for STL compliance.

Definition at line 120 of file sequence.h.

◆ size_type

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

Types for STL compliance.

Definition at line 124 of file sequence.h.

◆ value_type

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

Types for STL compliance.

Definition at line 119 of file sequence.h.

Constructor & Destructor Documentation

◆ SequenceImplementation() [1/4]

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

Default constructor.

Parameters
size_paramThe intial size of the gum::SequenceImplementation.

Definition at line 292 of file sequence_tpl.h.

292 :
293 _h_(size_param), _end_safe_{*this}, _rend_safe_{*this} {
295 _rend_safe_._setAtRend_();
296 _update_end_();
297 }
The internal class for storing (ordered) sequences of objects.
Definition sequence.h:109
void _update_end_() noexcept
A method to update the end iterator after changes in the sequence.
SequenceIteratorSafe< Key > _rend_safe_
Stores the rend iterator for fast access.
Definition sequence.h:501
SequenceImplementation(Size size_param=HashTableConst::default_size)
Default constructor.
SequenceIteratorSafe< Key > _end_safe_
Stores the end iterator for fast access.
Definition sequence.h:498
HashTable< Key, Idx > _h_
Keep track of the position of the element in v (for fast retrieval).
Definition sequence.h:488

References _end_safe_, _h_, and _rend_safe_.

Referenced by SequenceImplementation(), SequenceImplementation(), SequenceImplementation(), ~SequenceImplementation(), _copy_(), gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::_insert_(), operator!=(), operator<<(), operator<<(), operator=(), operator=(), and operator==().

Here is the caller graph for this function:

◆ SequenceImplementation() [2/4]

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

Initializer list constructor.

Parameters
listThe initializer list.

Definition at line 301 of file sequence_tpl.h.

302 : _end_safe_{*this}, _rend_safe_{*this} {
304 _rend_safe_._setAtRend_();
305 for (const auto& elt: list) {
306 insert(elt); // performs the _update_end_ ()
307 }
308 }
void insert(const Key &k)
Insert an element at the end of the sequence.

References SequenceImplementation(), _end_safe_, and _rend_safe_.

Here is the call graph for this function:

◆ SequenceImplementation() [3/4]

template<typename Key, bool Gen>
INLINE gum::SequenceImplementation< Key, Gen >::SequenceImplementation ( const SequenceImplementation< Key, 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 312 of file sequence_tpl.h.

313 : _end_safe_{*this}, _rend_safe_{*this} {
315 _rend_safe_._setAtRend_();
316 _copy_(aSeq); // performs the _update_end_ ()
317 }
void _copy_(const SequenceImplementation< Key, Gen > &aSeq)
Clears the current sequence and fill it with copies the element of aSeq.

References SequenceImplementation(), _end_safe_, and _rend_safe_.

Here is the call graph for this function:

◆ SequenceImplementation() [4/4]

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

Move constructor.

Parameters
aSeqThe gum::SequenceImplementation to move/

Definition at line 321 of file sequence_tpl.h.

322 :
325 _rend_safe_._setAtRend_();
326 _update_end_();
327 }
std::vector< Key * > _v_
The set of the elements stored into the sequence.
Definition sequence.h:491

References SequenceImplementation(), _end_safe_, _h_, _rend_safe_, _update_end_(), and _v_.

Here is the call graph for this function:

◆ ~SequenceImplementation()

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

Class destructor.

Definition at line 331 of file sequence_tpl.h.

References SequenceImplementation().

Referenced by gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::_insert_().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ _copy_()

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

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

Parameters
aSeqThe gum::SequenceImplementation to copy.

Definition at line 279 of file sequence_tpl.h.

279 {
280 clear();
281
282 for (Size i = 0; i < aSeq.size(); ++i) {
283 Key& new_key = const_cast< Key& >(_h_.insert(*(aSeq._v_[i]), i).first);
284 _v_.push_back(&new_key);
285 }
286
287 _update_end_();
288 }
void clear()
Clear the sequence.
Size size() const noexcept
Returns the size of the sequence.

References SequenceImplementation(), _h_, _v_, clear(), and size().

Referenced by gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::_insert_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _insert_()

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

Insert an element at the end of the sequence.

Parameters
bucketThe bucket holing the store to insert.

Referenced by gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::_insert_().

Here is the caller graph for this function:

◆ _update_end_()

template<typename Key>
INLINE void gum::SequenceImplementation< Key >::_update_end_ ( )
privatenoexcept

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

Definition at line 264 of file sequence_tpl.h.

264 {
265 _end_safe_._setAtEnd_();
266 }

References _end_safe_.

Referenced by SequenceImplementation(), gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::_insert_(), clear(), erase(), insert(), insert(), and operator=().

Here is the caller graph for this function:

◆ atPos()

template<typename Key>
INLINE const Key & gum::SequenceImplementation< Key >::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 459 of file sequence_tpl.h.

459 {
460 if (i >= _h_.size()) {
461 GUM_ERROR(OutOfBounds, "index " << i << " for a sequence of size" << _h_.size())
462 }
463
464 return *(_v_[i]);
465 }
#define GUM_ERROR(type, msg)
Definition exceptions.h:72

References _h_, and GUM_ERROR.

Referenced by gum::prm::StructuredInference< GUM_SCALAR >::_addEdgesInReducedGraph_(), gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::_insert_(), gum::prm::PRMClass< GUM_SCALAR >::_overloadReference_(), gum::Instantiation::_reorder_(), gum::prm::GSpan< GUM_SCALAR >::_subgraph_mining_(), back(), front(), operator[](), and swap().

Here is the caller graph for this function:

◆ back()

template<typename Key>
INLINE const Key & gum::SequenceImplementation< Key >::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 522 of file sequence_tpl.h.

522 {
523 return atPos(size() - 1);
524 }
const Key & atPos(Idx i) const
Returns the object at the pos i.

References atPos(), and size().

Referenced by gum::prm::PRMFactory< GUM_SCALAR >::_buildSlotChain_(), gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::_insert_(), and gum::prm::PRMClass< GUM_SCALAR >::_overloadReference_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ begin()

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

Returns an unsafe begin iterator.

Returns
Returns an unsafe begin iterator.

Definition at line 604 of file sequence_tpl.h.

604 {
605 return SequenceIterator< Key >{*this};
606 }

Referenced by gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::_insert_(), and gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::clean().

Here is the caller graph for this function:

◆ beginSafe()

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

Returns a safe begin iterator.

Returns
Returns a safe begin iterator.

Definition at line 576 of file sequence_tpl.h.

576 {
577 return SequenceIteratorSafe< Key >{*this};
578 }
friend class SequenceIteratorSafe< Key >
Friends to speed up access.
Definition sequence.h:112

References SequenceIteratorSafe< Key >.

Referenced by gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::_insert_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear()

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

Clear the sequence.

Definition at line 270 of file sequence_tpl.h.

270 {
271 _h_.clear();
272 _v_.clear();
273 _update_end_();
274 }

References _h_, _update_end_(), and _v_.

Referenced by _copy_(), and gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::_insert_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ emplace() [1/2]

template<typename Key, bool Gen>
template<typename... Args>
void gum::SequenceImplementation< Key, 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.

Referenced by gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::_insert_().

Here is the caller graph for this function:

◆ emplace() [2/2]

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

Definition at line 388 of file sequence_tpl.h.

388 {
390 Key& new_key = const_cast< Key& >(_h_.insert(std::move(key), _h_.size()).first);
391 _v_.push_back(&new_key);
392 _update_end_();
393 }

◆ empty()

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

Return true if empty.

Returns
Return true if empty.

Definition at line 64 of file sequence_tpl.h.

64 {
65 return _h_.empty();
66 }

References _h_.

Referenced by gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::_insert_().

Here is the caller graph for this function:

◆ end()

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

Returns the unsafe end iterator.

Returns
Returns the unsafe end iterator.

Definition at line 610 of file sequence_tpl.h.

610 {
611 return _end_safe_;
612 }

References _end_safe_.

Referenced by gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::_insert_(), and gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::clean().

Here is the caller graph for this function:

◆ endSafe()

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

Returns the safe end iterator.

Returns
Returns the safe end iterator.

Definition at line 583 of file sequence_tpl.h.

583 {
584 return _end_safe_;
585 }

References _end_safe_.

Referenced by gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::_insert_().

Here is the caller graph for this function:

◆ erase() [1/2]

template<typename Key>
INLINE void gum::SequenceImplementation< Key >::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 433 of file sequence_tpl.h.

433 {
434 if (iter.pos() >= size()) return;
435
436 // erase the element
437 Idx pos = iter.pos();
438 Key* key = _v_[pos];
439 _v_.erase(_v_.begin() + pos);
440
441 for (Idx i = pos, nb_elts = _h_.size() - 1; i < nb_elts; ++i) {
442 --_h_[*(_v_[i])];
443 }
444 _h_.erase(*key);
445
446 _update_end_();
447 }
Idx pos(const Key &key) const
Returns the position of the object passed in argument (if it exists).

References _h_, _update_end_(), _v_, pos(), and size().

Here is the call graph for this function:

◆ erase() [2/2]

template<typename Key, bool Gen>
INLINE void gum::SequenceImplementation< Key, 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 413 of file sequence_tpl.h.

413 {
414 // get the position of the element to remove
415 Idx pos;
416
417 try {
418 pos = _h_[k];
419 } catch (NotFound const&) { return; }
420
421 // erase the element
422 _v_.erase(_v_.begin() + pos);
423 for (Idx i = pos, nb_elts = _h_.size() - 1; i < nb_elts; ++i) {
424 --_h_[*(_v_[i])];
425 }
426 _h_.erase(k);
427
428 _update_end_();
429 }

References _h_, and pos().

Referenced by gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::_insert_(), gum::prm::PRMClass< GUM_SCALAR >::_overloadReference_(), and operator>>().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ exists()

template<typename Key, bool Gen>
INLINE bool gum::SequenceImplementation< Key >::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 363 of file sequence_tpl.h.

363 {
364 return _h_.exists(k);
365 }

References _h_.

Referenced by gum::prm::SVE< GUM_SCALAR >::_initElimOrder_(), gum::prm::SVED< GUM_SCALAR >::_initElimOrder_(), gum::prm::gspan::DFSTree< GUM_SCALAR >::_initialiaze_root_(), gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::_insert_(), gum::prm::GSpan< GUM_SCALAR >::_subgraph_mining_(), gum::prm::PRMFactory< GUM_SCALAR >::addAttribute(), gum::prm::gspan::SearchStrategy< GUM_SCALAR >::computeCost_(), and gum::Sequence< Key >::diffSet().

Here is the caller graph for this function:

◆ front()

template<typename Key>
INLINE const Key & gum::SequenceImplementation< Key >::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 516 of file sequence_tpl.h.

516 {
517 return atPos(0);
518 }

References atPos().

Referenced by gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::_insert_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ insert() [1/2]

template<typename Key, bool Gen>
INLINE void gum::SequenceImplementation< Key, 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 369 of file sequence_tpl.h.

369 {
370 // k will be added at the end. Insert the new key into the hashtable
371 Key& new_key = const_cast< Key& >(_h_.insert(k, _h_.size()).first);
372 _v_.push_back(&new_key);
373 _update_end_();
374 }

References _h_, _update_end_(), and _v_.

Referenced by gum::prm::PRMFactory< GUM_SCALAR >::_buildSlotChain_(), gum::prm::SVE< GUM_SCALAR >::_initElimOrder_(), gum::prm::SVED< GUM_SCALAR >::_initElimOrder_(), gum::prm::gspan::DFSTree< GUM_SCALAR >::_initialiaze_root_(), gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::_insert_(), gum::prm::PRMClass< GUM_SCALAR >::_overloadReference_(), gum::prm::gspan::SearchStrategy< GUM_SCALAR >::computeCost_(), gum::prm::gspan::DFSTree< GUM_SCALAR >::growPattern(), operator<<(), operator<<(), and gum::SequenceImplementation< const gum::DiscreteVariable *, std::is_scalar< const gum::DiscreteVariable * >::value >::operator==().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ insert() [2/2]

template<typename Key, bool Gen>
INLINE void gum::SequenceImplementation< Key, 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 378 of file sequence_tpl.h.

378 {
379 // k will be added at the end. Insert the new key into the hashtable
380 Key& new_key = const_cast< Key& >(_h_.insert(std::move(k), _h_.size()).first);
381 _v_.push_back(&new_key);
382 _update_end_();
383 }

References _h_, _update_end_(), and _v_.

Here is the call graph for this function:

◆ operator!=()

template<typename Key, bool Gen>
INLINE bool gum::SequenceImplementation< Key >::operator!= ( const SequenceImplementation< Key, 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.

Parameters
kThe other gum::SequenceImplementation.

Returns true if both gum::SequenceImplementation are not equal.

Definition at line 561 of file sequence_tpl.h.

562 {
563 return !operator==(k);
564 }
bool operator==(const SequenceImplementation< Key, Gen > &k) const
Returns true if the content of k equals that of *this.

References SequenceImplementation(), and gum::operator==().

Referenced by gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::_insert_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator<<() [1/2]

template<typename Key, bool Gen>
INLINE SequenceImplementation< Key, Gen > & gum::SequenceImplementation< Key, 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 397 of file sequence_tpl.h.

398 {
399 insert(k);
400 return *this;
401 }

References SequenceImplementation(), and insert().

Referenced by gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::_insert_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator<<() [2/2]

template<typename Key, bool Gen>
INLINE SequenceImplementation< Key, Gen > & gum::SequenceImplementation< Key, 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 405 of file sequence_tpl.h.

406 {
408 return *this;
409 }

References SequenceImplementation(), and insert().

Here is the call graph for this function:

◆ operator=() [1/2]

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

Copy operator.

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

Definition at line 337 of file sequence_tpl.h.

338 {
339 // avoid self assignment
340 if (&aSeq != this) {
341 _copy_(aSeq); // performs the _update_end_ ()
342 }
343
344 return *this;
345 }

References SequenceImplementation().

Referenced by gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::_insert_(), gum::Sequence< Key >::operator=(), and gum::Sequence< Key >::operator=().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=() [2/2]

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

Move operator.

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

Definition at line 350 of file sequence_tpl.h.

350 {
351 // avoid self assignment
352 if (&aSeq != this) {
355 _update_end_();
356 }
357
358 return *this;
359 }

References SequenceImplementation(), _h_, _update_end_(), and _v_.

Here is the call graph for this function:

◆ operator==()

template<typename Key, bool Gen>
bool gum::SequenceImplementation< Key >::operator== ( const SequenceImplementation< Key, 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.

Parameters
kThe other gum::SequenceImplementation.

Returns true if both gum::SequenceImplementation are equal.

Definition at line 548 of file sequence_tpl.h.

549 {
550 if (size() != k.size()) return false;
551 else {
552 for (Idx i = 0; i < size(); ++i)
553 if (*_v_[i] != *(k._v_[i])) return false;
554 }
555
556 return true;
557 }

References SequenceImplementation(), _v_, and size().

Referenced by gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::_insert_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator>>()

template<typename Key, bool Gen>
INLINE SequenceImplementation< Key, true > & gum::SequenceImplementation< Key >::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 452 of file sequence_tpl.h.

452 {
453 erase(k);
454 return *this;
455 }
void erase(const Key &k)
Remove an element from the sequence.

References erase().

Referenced by gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::_insert_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator[]()

template<typename Key>
INLINE const Key & gum::SequenceImplementation< Key >::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 469 of file sequence_tpl.h.

469 {
470 return atPos(i);
471 }

References atPos().

Referenced by gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::_insert_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pos()

template<typename Key, bool Gen>
INLINE Idx gum::SequenceImplementation< Key >::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 475 of file sequence_tpl.h.

475 {
476 return _h_[key];
477 }

References _h_.

Referenced by gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::_insert_(), gum::prm::GSpan< GUM_SCALAR >::_subgraph_mining_(), gum::MultiDimArray< GUM_SCALAR >::erase(), gum::MultiDimWithOffset< GUM_SCALAR >::erase(), erase(), and erase().

Here is the caller graph for this function:

◆ rbegin()

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

Returns an unsafe rbegin iterator.

Returns
Returns an unsafe rbegin iterator.

Definition at line 616 of file sequence_tpl.h.

616 {
618 it._setPos_(size() - 1);
619 return it;
620 }

References size().

Referenced by gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::_insert_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rbeginSafe()

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

Returns a safe rbegin iterator.

Returns
Returns a safe rbegin iterator.

Definition at line 589 of file sequence_tpl.h.

589 {
591 it._setPos_(size() - 1);
592 return it;
593 }

References SequenceIteratorSafe< Key >, and size().

Referenced by gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::_insert_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rend()

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

Returns the unsafe rend iterator.

Returns
Returns the unsafe rend iterator.

Definition at line 624 of file sequence_tpl.h.

624 {
625 return _rend_safe_;
626 }

References _rend_safe_.

Referenced by gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::_insert_().

Here is the caller graph for this function:

◆ rendSafe()

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

Returns the safe rend iterator.

Returns
Returns the safe rend iterator.

Definition at line 598 of file sequence_tpl.h.

598 {
599 return _rend_safe_;
600 }

References _rend_safe_.

Referenced by gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::_insert_().

Here is the caller graph for this function:

◆ resize()

template<typename Key>
INLINE void gum::SequenceImplementation< Key >::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 630 of file sequence_tpl.h.

630 {
631 if (new_size < _h_.size()) return;
632
633 _h_.resize(new_size);
634 _v_.reserve(new_size);
635 }

References _h_, and _v_.

Referenced by gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::_insert_().

Here is the caller graph for this function:

◆ setAtPos() [1/2]

template<typename Key, bool Gen>
INLINE void gum::SequenceImplementation< Key, 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 481 of file sequence_tpl.h.

481 {
482 if (i >= _h_.size()) { GUM_ERROR(NotFound, "index too large") }
483
484 Key& new_key = const_cast< Key& >(_h_.insert(newKey, i).first);
485 _h_.erase(*(_v_[i]));
486 _v_[i] = &new_key;
487 }

Referenced by gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::_insert_().

Here is the caller graph for this function:

◆ setAtPos() [2/2]

template<typename Key, bool Gen>
INLINE void gum::SequenceImplementation< Key, 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 491 of file sequence_tpl.h.

491 {
492 if (i >= _h_.size()) { GUM_ERROR(NotFound, "index too large") }
493
494 Key& new_key = const_cast< Key& >(_h_.insert(std::move(newKey), i).first);
495 _h_.erase(*(_v_[i]));
496 _v_[i] = &new_key;
497 }

References _h_, _v_, and GUM_ERROR.

◆ size()

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

Returns the size of the sequence.

Returns
Returns the size of the sequence.

Definition at line 58 of file sequence_tpl.h.

58 {
59 return _h_.size();
60 }

References _h_.

Referenced by gum::prm::StructuredInference< GUM_SCALAR >::_addEdgesInReducedGraph_(), gum::prm::PRMFactory< GUM_SCALAR >::_buildSlotChain_(), _copy_(), gum::Instantiation::_init_(), gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::_insert_(), gum::prm::PRMClass< GUM_SCALAR >::_overloadReference_(), gum::Instantiation::_reorder_(), back(), gum::MultiDimArray< GUM_SCALAR >::erase(), gum::MultiDimWithOffset< GUM_SCALAR >::erase(), erase(), operator==(), rbegin(), and rbeginSafe().

Here is the caller graph for this function:

◆ swap()

template<typename Key>
INLINE void gum::SequenceImplementation< Key >::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 501 of file sequence_tpl.h.

501 {
502 if (i == j) return;
503
504 Key& ki = const_cast< Key& >(atPos(i));
505 Key& kj = const_cast< Key& >(atPos(j));
506
507 _h_[ki] = j;
508 _h_[kj] = i;
509
510 _v_[i] = &kj;
511 _v_[j] = &ki;
512 }

References atPos().

Referenced by gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::_insert_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toString()

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

Displays the content of the sequence.

Returns
The content of the sequence.

Definition at line 528 of file sequence_tpl.h.

528 {
530 stream << "[";
531
532 if (!_h_.empty()) {
533 stream << 0 << ":" << *_v_[0];
534
535 for (Idx i = 1; i < _h_.size(); ++i) {
536 stream << " - " << i << ":" << *_v_[i];
537 }
538 }
539
540 stream << "]";
541
542 std::string res = stream.str();
543 return res;
544 }

References _h_, and _v_.

Referenced by gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::_insert_(), gum::operator<<(), gum::operator<<(), and gum::operator<<().

Here is the caller graph for this function:

◆ Sequence< Key >

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

Friends to speed up access.

Definition at line 1357 of file sequence.h.

◆ SequenceIteratorSafe< Key >

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

Friends to speed up access.

Definition at line 1357 of file sequence.h.

Referenced by beginSafe(), and rbeginSafe().

Member Data Documentation

◆ _end_safe_

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

Stores the end iterator for fast access.

Definition at line 498 of file sequence.h.

Referenced by SequenceImplementation(), SequenceImplementation(), SequenceImplementation(), SequenceImplementation(), _update_end_(), end(), and endSafe().

◆ _h_

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

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

Definition at line 488 of file sequence.h.

Referenced by SequenceImplementation(), SequenceImplementation(), _copy_(), atPos(), clear(), empty(), erase(), erase(), exists(), insert(), insert(), operator=(), pos(), resize(), setAtPos(), size(), and toString().

◆ _rend_safe_

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

Stores the rend iterator for fast access.

Definition at line 501 of file sequence.h.

Referenced by SequenceImplementation(), SequenceImplementation(), SequenceImplementation(), SequenceImplementation(), rend(), and rendSafe().

◆ _v_

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

The set of the elements stored into the sequence.

Definition at line 491 of file sequence.h.

Referenced by SequenceImplementation(), _copy_(), clear(), erase(), insert(), insert(), operator=(), operator==(), resize(), setAtPos(), and toString().


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