![]() |
aGrUM
0.20.3
a C++ library for (probabilistic) graphical models
|
The internal class for storing (ordered) sequences of objects. More...
#include <agrum/tools/core/sequence.h>
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_safe & | endSafe () const noexcept |
Returns the safe end iterator. More... | |
const iterator_safe & | rendSafe () 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 iterator & | end () const noexcept |
Returns the unsafe end iterator. More... | |
const iterator & | rend () 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... | |
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.
Key | The elements type stored in the sequence. |
Alloc | The values allocator. |
Gen | Used for meta-programation. |
Definition at line 89 of file sequence.h.
using gum::SequenceImplementation< Key, Alloc, Gen >::allocator_type = Alloc |
Types for STL compliance.
Definition at line 108 of file sequence.h.
using gum::SequenceImplementation< Key, Alloc, Gen >::const_iterator = SequenceIterator< Key > |
Types for STL compliance.
Definition at line 110 of file sequence.h.
using gum::SequenceImplementation< Key, Alloc, Gen >::const_iterator_safe = SequenceIteratorSafe< Key > |
Types for STL compliance.
Definition at line 112 of file sequence.h.
using gum::SequenceImplementation< Key, Alloc, Gen >::const_pointer = const Key* |
Types for STL compliance.
Definition at line 105 of file sequence.h.
using gum::SequenceImplementation< Key, Alloc, Gen >::const_reference = const Key& |
Types for STL compliance.
Definition at line 103 of file sequence.h.
using gum::SequenceImplementation< Key, Alloc, Gen >::difference_type = std::ptrdiff_t |
Types for STL compliance.
Definition at line 107 of file sequence.h.
using gum::SequenceImplementation< Key, Alloc, Gen >::iterator = SequenceIterator< Key > |
Types for STL compliance.
Definition at line 109 of file sequence.h.
using gum::SequenceImplementation< Key, Alloc, Gen >::iterator_safe = SequenceIteratorSafe< Key > |
Types for STL compliance.
Definition at line 111 of file sequence.h.
using gum::SequenceImplementation< Key, Alloc, Gen >::pointer = Key* |
Types for STL compliance.
Definition at line 104 of file sequence.h.
using gum::SequenceImplementation< Key, Alloc, Gen >::reference = Key& |
Types for STL compliance.
Definition at line 102 of file sequence.h.
using gum::SequenceImplementation< Key, Alloc, Gen >::size_type = std::size_t |
Types for STL compliance.
Definition at line 106 of file sequence.h.
using gum::SequenceImplementation< Key, Alloc, Gen >::value_type = Key |
Types for STL compliance.
Definition at line 101 of file sequence.h.
|
private |
Default constructor.
size_param | The intial size of the gum::SequenceImplementation. |
Definition at line 287 of file sequence_tpl.h.
|
private |
Initializer list constructor.
list | The initializer list. |
Definition at line 296 of file sequence_tpl.h.
|
private |
Copy constructor.
aSeq | The sequence the elements of which will be copied. |
Definition at line 309 of file sequence_tpl.h.
|
private |
Generalised copy constructor.
OtherAlloc | The other gum::SequenceImplementation allocator. |
aSeq | The sequence the elements of which will be copied. |
|
private |
Move constructor.
aSeq | The gum::SequenceImplementation to move/ |
Definition at line 332 of file sequence_tpl.h.
|
noexcept |
Class destructor.
Definition at line 343 of file sequence_tpl.h.
INLINE gum::SequenceImplementation< Key, Alloc, Gen >::SequenceImplementation | ( | const SequenceImplementation< Key, OtherAlloc, Gen > & | aSeq | ) |
Definition at line 321 of file sequence_tpl.h.
gum::SequenceImplementation< Key, Alloc, Gen >::SequenceImplementation | ( | const SequenceImplementation< Key, Alloc, true > & | aSeq | ) |
Definition at line 723 of file sequence_tpl.h.
gum::SequenceImplementation< Key, Alloc, Gen >::SequenceImplementation | ( | const SequenceImplementation< Key, OtherAlloc, true > & | aSeq | ) |
Definition at line 735 of file sequence_tpl.h.
INLINE gum::SequenceImplementation< Key, Alloc, Gen >::SequenceImplementation | ( | SequenceImplementation< Key, Alloc, true > && | aSeq | ) |
Definition at line 746 of file sequence_tpl.h.
INLINE void gum::SequenceImplementation< Key, Alloc, Gen >::_copy_ | ( | const SequenceImplementation< Key, OtherAlloc, Gen > & | aSeq | ) |
Definition at line 273 of file sequence_tpl.h.
|
private |
Clears the current sequence and fill it with copies the element of aSeq.
OtherAlloc | The other gum::SequenceImplementation allocator. |
aSeq | The gum::SequenceImplementation to copy. |
INLINE void gum::SequenceImplementation< Key, Alloc, Gen >::_copy_ | ( | const SequenceImplementation< Key, OtherAlloc, true > & | aSeq | ) |
Definition at line 687 of file sequence_tpl.h.
|
private |
Insert an element at the end of the sequence.
bucket | The bucket holing the store to insert. |
|
privatenoexcept |
A method to update the end iterator after changes in the sequence.
Definition at line 258 of file sequence_tpl.h.
INLINE const Key & gum::SequenceImplementation< Key, Alloc >::atPos | ( | Idx | i | ) | const |
Returns the object at the pos i.
i | The position of the element to return. |
NotFound | Raised if the element does not exist. |
Definition at line 483 of file sequence_tpl.h.
INLINE const Key & gum::SequenceImplementation< Key, Alloc >::back | ( | ) | const |
Returns the last element of the sequence.
NotFound | Raised if the sequence is empty. |
Definition at line 546 of file sequence_tpl.h.
INLINE SequenceIterator< Key > gum::SequenceImplementation< Key, Alloc >::begin | ( | ) | const |
Returns an unsafe begin iterator.
Definition at line 631 of file sequence_tpl.h.
INLINE SequenceIteratorSafe< Key > gum::SequenceImplementation< Key, Alloc >::beginSafe | ( | ) | const |
Returns a safe begin iterator.
Definition at line 603 of file sequence_tpl.h.
INLINE void gum::SequenceImplementation< Key, Alloc >::clear | ( | ) |
Clear the sequence.
Definition at line 264 of file sequence_tpl.h.
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.
Args | The arguments types passed to the constructor. |
args | The arguments passed to the constructor. |
DuplicateElement | Raised if the sequence contains already k. |
INLINE void gum::SequenceImplementation< Key, Alloc >::emplace | ( | Args &&... | args | ) |
Definition at line 412 of file sequence_tpl.h.
|
noexcept |
Return true if empty.
Definition at line 43 of file sequence_tpl.h.
|
noexcept |
Returns the unsafe end iterator.
Definition at line 638 of file sequence_tpl.h.
|
noexcept |
Returns the safe end iterator.
Definition at line 610 of file sequence_tpl.h.
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).
k | The element to remove. |
Definition at line 437 of file sequence_tpl.h.
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)
k | The iterator poiting to the element to remove. |
Definition at line 457 of file sequence_tpl.h.
INLINE bool gum::SequenceImplementation< Key, Alloc >::exists | ( | const Key & | k | ) | const |
Check the existence of k in the sequence.
The complexity is \(o(1)\).
k | The key to check for existence. |
Definition at line 387 of file sequence_tpl.h.
INLINE const Key & gum::SequenceImplementation< Key, Alloc >::front | ( | ) | const |
Returns the first element of the element.
NotFound | Raised if the sequence is empty. |
Definition at line 540 of file sequence_tpl.h.
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)\).
k | The element to insert. |
DuplicateElement | Raised if the sequence contains already k. |
Definition at line 393 of file sequence_tpl.h.
INLINE void gum::SequenceImplementation< Key, Alloc, Gen >::insert | ( | Key && | k | ) |
Move an element at the end of the sequence.
The complexity is \(o(1)\).
k | The element to insert. |
DuplicateElement | Raised if the sequence contains already k. |
Definition at line 402 of file sequence_tpl.h.
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.
OtherAlloc | The other gum::SequenceImplementation allocator. |
k | The other gum::SequenceImplementation. Returns true if both gum::SequenceImplementation are not equal. |
INLINE bool gum::SequenceImplementation< Key, Alloc, Gen >::operator!= | ( | const SequenceImplementation< Key, OtherAlloc, Gen > & | k | ) | const |
Definition at line 588 of file sequence_tpl.h.
INLINE bool gum::SequenceImplementation< Key, Alloc, Gen >::operator!= | ( | const SequenceImplementation< Key, OtherAlloc, true > & | k | ) | const |
Definition at line 971 of file sequence_tpl.h.
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).
k | The key we wish to insert in the sequence. |
DuplicateElement | Raised if the sequence contains already k. |
Definition at line 422 of file sequence_tpl.h.
INLINE SequenceImplementation< Key, Alloc, Gen > & gum::SequenceImplementation< Key, Alloc, Gen >::operator<< | ( | Key && | k | ) |
Insert k at the end of the sequence (synonym for insert).
k | The key we wish to insert in the sequence. |
DuplicateElement | Raised if the sequence contains already k. |
Definition at line 430 of file sequence_tpl.h.
|
private |
Copy operator.
aSeq | The sequence to copy. |
Definition at line 350 of file sequence_tpl.h.
|
private |
Generalized opy operator.
OtherAlloc | The other gum::SequenceImplementation allocator. |
aSeq | The sequence to copy. |
|
private |
Move operator.
aSeq | The sequence to move. |
Definition at line 373 of file sequence_tpl.h.
INLINE SequenceImplementation< Key, Alloc, Gen >& gum::SequenceImplementation< Key, Alloc, Gen >::operator= | ( | const SequenceImplementation< Key, OtherAlloc, Gen > & | aSeq | ) |
Definition at line 364 of file sequence_tpl.h.
INLINE SequenceImplementation< Key, Alloc, true >& gum::SequenceImplementation< Key, Alloc, Gen >::operator= | ( | const SequenceImplementation< Key, OtherAlloc, true > & | aSeq | ) |
Definition at line 776 of file sequence_tpl.h.
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.
OtherAlloc | The other gum::SequenceImplementation allocator. |
k | The other gum::SequenceImplementation. Returns true if both gum::SequenceImplementation are equal. |
Definition at line 573 of file sequence_tpl.h.
bool gum::SequenceImplementation< Key, Alloc, Gen >::operator== | ( | const SequenceImplementation< Key, OtherAlloc, true > & | k | ) | const |
Definition at line 956 of file sequence_tpl.h.
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.
k | The key we wish to remove. |
Definition at line 476 of file sequence_tpl.h.
INLINE const Key & gum::SequenceImplementation< Key, Alloc >::operator[] | ( | Idx | i | ) | const |
Returns the element at position i (synonym for atPos).
i | The position of the element to return. |
OutOfBounds | Raised if the element does not exist. |
Definition at line 493 of file sequence_tpl.h.
INLINE Idx gum::SequenceImplementation< Key, Alloc >::pos | ( | const Key & | key | ) | const |
Returns the position of the object passed in argument (if it exists).
key | The element for which the positon is returned. |
NotFound | Raised if the element does not exist. |
Definition at line 499 of file sequence_tpl.h.
INLINE SequenceIterator< Key > gum::SequenceImplementation< Key, Alloc >::rbegin | ( | ) | const |
Returns an unsafe rbegin iterator.
Definition at line 644 of file sequence_tpl.h.
INLINE SequenceIteratorSafe< Key > gum::SequenceImplementation< Key, Alloc >::rbeginSafe | ( | ) | const |
Returns a safe rbegin iterator.
Definition at line 616 of file sequence_tpl.h.
|
noexcept |
Returns the unsafe rend iterator.
Definition at line 653 of file sequence_tpl.h.
|
noexcept |
Returns the safe rend iterator.
Definition at line 625 of file sequence_tpl.h.
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.
new_size | The internal structure new size. |
Definition at line 659 of file sequence_tpl.h.
INLINE void gum::SequenceImplementation< Key, Alloc, Gen >::setAtPos | ( | Idx | i, |
const Key & | newKey | ||
) |
Change the value.
i | The element's position. |
newKey | The element's new value. |
NotFound | Raised if the element does not exist. |
DuplicateElement | Raised if newKey alreay exists. |
Definition at line 505 of file sequence_tpl.h.
INLINE void gum::SequenceImplementation< Key, Alloc, Gen >::setAtPos | ( | Idx | i, |
Key && | newKey | ||
) |
Change the value.
i | The element's position. |
newKey | The element's new value. |
NotFound | Raised if the element does not exist. |
DuplicateElement | Raised if newKey alreay exists. |
Definition at line 515 of file sequence_tpl.h.
|
noexcept |
Returns the size of the sequence.
Definition at line 37 of file sequence_tpl.h.
INLINE void gum::SequenceImplementation< Key, Alloc >::swap | ( | Idx | i, |
Idx | j | ||
) |
Swap index.
i | The index of the first elt to swap. |
j | The index of the other elt to swap. |
Definition at line 525 of file sequence_tpl.h.
std::string gum::SequenceImplementation< Key, Alloc >::toString | ( | ) | const |
Displays the content of the sequence.
Definition at line 552 of file sequence_tpl.h.
|
friend |
Friends to speed up access.
Definition at line 93 of file sequence.h.
|
friend |
Friends to speed up access.
Definition at line 95 of file sequence.h.
|
friend |
Friends to speed up access.
Definition at line 94 of file sequence.h.
|
private |
Stores the end iterator for fast access.
Definition at line 508 of file sequence.h.
|
private |
Keep track of the position of the element in v (for fast retrieval).
Definition at line 498 of file sequence.h.
|
private |
Stores the rend iterator for fast access.
Definition at line 511 of file sequence.h.
|
private |
The set of the elements stored into the sequence.
Definition at line 501 of file sequence.h.