![]() |
aGrUM
0.20.3
a C++ library for (probabilistic) graphical models
|
The generic class for storing (ordered) sequences of objects. More...
#include <agrum/tools/core/sequence.h>
Public Member Functions | |
template<typename OtherAlloc > | |
INLINE | Sequence (const Sequence< Key, OtherAlloc > &aSeq) |
template<typename OtherAlloc > | |
INLINE Sequence< Key, Alloc > & | operator= (const Sequence< Key, OtherAlloc > &aSeq) |
bool | operator== (const SequenceImplementation< Key, OtherAlloc, true > &k) const |
INLINE bool | operator!= (const SequenceImplementation< Key, OtherAlloc, Gen > &k) const |
INLINE bool | operator!= (const SequenceImplementation< Key, OtherAlloc, true > &k) const |
INLINE void | emplace (Args &&... args) |
INLINE void | _copy_ (const SequenceImplementation< Key, OtherAlloc, Gen > &aSeq) |
INLINE void | _copy_ (const SequenceImplementation< Key, OtherAlloc, true > &aSeq) |
Constructors / Destructors | |
Sequence (Size size_param=HashTableConst::default_size) | |
Default constructor. More... | |
Sequence (std::initializer_list< Key > list) | |
Initializer list constructor. More... | |
Sequence (const Sequence< Key, Alloc > &aSeq) | |
Copy constructor. More... | |
template<typename OtherAlloc > | |
Sequence (const Sequence< Key, OtherAlloc > &aSeq) | |
Generalised copy constructor. More... | |
Sequence (Sequence< Key, Alloc > &&aSeq) | |
Move constructor. More... | |
~Sequence () noexcept | |
Class destructor. More... | |
Operators | |
Sequence< Key, Alloc > & | operator= (const Sequence< Key, Alloc > &aSeq) |
Copy operator. More... | |
template<typename OtherAlloc > | |
Sequence< Key, Alloc > & | operator= (const Sequence< Key, OtherAlloc > &aSeq) |
Generalized opy operator. More... | |
Sequence< Key, Alloc > & | operator= (Sequence< Key, Alloc > &&aSeq) |
Move operator. More... | |
Accessors / Modifiers | |
template<typename OtherAlloc > | |
Set< Key, Alloc > | diffSet (const Sequence< Key, OtherAlloc > &seq) const |
Difference between two sequences as a Set<Key> = this \ seq. 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... | |
bool | operator== (const SequenceImplementation< Key, OtherAlloc, Gen > &k) const |
Returns true if the content of k equals that of *this. More... | |
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... | |
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 | Implementation = SequenceImplementation< Key, Alloc, std::is_scalar< Key >::value > |
The gum::Sequence implementation. More... | |
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... | |
The generic class for storing (ordered) sequences of objects.
A gum::Sequence<Key> is quite similar to a std::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 gum::Sequence<Key> 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.
Key | The elements type stored in the sequence. |
Alloc | The values allocator. |
Definition at line 1017 of file sequence.h.
using gum::Sequence< Key, Alloc >::allocator_type = Alloc |
Types for STL compliance.
Definition at line 1028 of file sequence.h.
using gum::Sequence< Key, Alloc >::const_iterator = SequenceIterator< Key > |
Types for STL compliance.
Definition at line 1030 of file sequence.h.
using gum::Sequence< Key, Alloc >::const_iterator_safe = SequenceIteratorSafe< Key > |
Types for STL compliance.
Definition at line 1032 of file sequence.h.
using gum::Sequence< Key, Alloc >::const_pointer = const Key* |
Types for STL compliance.
Definition at line 1025 of file sequence.h.
using gum::Sequence< Key, Alloc >::const_reference = const Key& |
Types for STL compliance.
Definition at line 1023 of file sequence.h.
using gum::Sequence< Key, Alloc >::difference_type = std::ptrdiff_t |
Types for STL compliance.
Definition at line 1027 of file sequence.h.
using gum::Sequence< Key, Alloc >::Implementation = SequenceImplementation< Key, Alloc, std::is_scalar< Key >::value > |
The gum::Sequence implementation.
Definition at line 1036 of file sequence.h.
using gum::Sequence< Key, Alloc >::iterator = SequenceIterator< Key > |
Types for STL compliance.
Definition at line 1029 of file sequence.h.
using gum::Sequence< Key, Alloc >::iterator_safe = SequenceIteratorSafe< Key > |
Types for STL compliance.
Definition at line 1031 of file sequence.h.
using gum::Sequence< Key, Alloc >::pointer = Key* |
Types for STL compliance.
Definition at line 1024 of file sequence.h.
using gum::Sequence< Key, Alloc >::reference = Key& |
Types for STL compliance.
Definition at line 1022 of file sequence.h.
using gum::Sequence< Key, Alloc >::size_type = std::size_t |
Types for STL compliance.
Definition at line 1026 of file sequence.h.
using gum::Sequence< Key, Alloc >::value_type = Key |
Types for STL compliance.
Definition at line 1021 of file sequence.h.
INLINE gum::Sequence< Key, Alloc >::Sequence | ( | Size | size_param = HashTableConst::default_size | ) |
Default constructor.
size_param | The intial size of the gum::SequenceImplementation. |
Definition at line 1056 of file sequence_tpl.h.
INLINE gum::Sequence< Key, Alloc >::Sequence | ( | std::initializer_list< Key > | list | ) |
Initializer list constructor.
list | The initializer list. |
Definition at line 1063 of file sequence_tpl.h.
INLINE gum::Sequence< Key, Alloc >::Sequence | ( | const Sequence< Key, Alloc > & | aSeq | ) |
Copy constructor.
aSeq | The sequence the elements of which will be copied. |
Definition at line 1071 of file sequence_tpl.h.
gum::Sequence< Key, Alloc >::Sequence | ( | const Sequence< Key, OtherAlloc > & | aSeq | ) |
Generalised copy constructor.
OtherAlloc | The other gum::Sequence allocator. |
aSeq | The sequence the elements of which will be copied. |
INLINE gum::Sequence< Key, Alloc >::Sequence | ( | Sequence< Key, Alloc > && | aSeq | ) |
Move constructor.
aSeq | The gum::Sequence to move/ |
Definition at line 1088 of file sequence_tpl.h.
|
noexcept |
Class destructor.
Definition at line 1096 of file sequence_tpl.h.
INLINE gum::Sequence< Key, Alloc >::Sequence | ( | const Sequence< Key, OtherAlloc > & | aSeq | ) |
Definition at line 1080 of file sequence_tpl.h.
|
inherited |
Definition at line 273 of file sequence_tpl.h.
|
inherited |
Definition at line 687 of file sequence_tpl.h.
|
inherited |
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.
|
inherited |
Returns the last element of the sequence.
NotFound | Raised if the sequence is empty. |
Definition at line 546 of file sequence_tpl.h.
|
inherited |
Returns an unsafe begin iterator.
Definition at line 631 of file sequence_tpl.h.
|
inherited |
Returns a safe begin iterator.
Definition at line 603 of file sequence_tpl.h.
|
inherited |
Clear the sequence.
Definition at line 264 of file sequence_tpl.h.
Set< Key, Alloc > gum::Sequence< Key, Alloc >::diffSet | ( | const Sequence< Key, OtherAlloc > & | seq | ) | const |
Difference between two sequences as a Set<Key> = this \ seq.
seq | The gum::Sequence to substract of this. |
Definition at line 1128 of file sequence_tpl.h.
|
inherited |
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. |
|
inherited |
Definition at line 412 of file sequence_tpl.h.
|
noexceptinherited |
Return true if empty.
Definition at line 43 of file sequence_tpl.h.
|
noexceptinherited |
Returns the unsafe end iterator.
Definition at line 638 of file sequence_tpl.h.
|
noexceptinherited |
Returns the safe end iterator.
Definition at line 610 of file sequence_tpl.h.
|
inherited |
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.
|
inherited |
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.
|
inherited |
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.
|
inherited |
Returns the first element of the element.
NotFound | Raised if the sequence is empty. |
Definition at line 540 of file sequence_tpl.h.
|
inherited |
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.
|
inherited |
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.
|
inherited |
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. |
|
inherited |
Definition at line 588 of file sequence_tpl.h.
|
inherited |
Definition at line 971 of file sequence_tpl.h.
|
inherited |
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.
|
inherited |
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.
INLINE Sequence< Key, Alloc > & gum::Sequence< Key, Alloc >::operator= | ( | const Sequence< Key, Alloc > & | aSeq | ) |
Copy operator.
aSeq | The sequence to copy. |
Definition at line 1104 of file sequence_tpl.h.
Sequence< Key, Alloc >& gum::Sequence< Key, Alloc >::operator= | ( | const Sequence< Key, OtherAlloc > & | aSeq | ) |
Generalized opy operator.
otheralloc | The other gum::sequenceimplementation allocator. |
aSeq | The sequence to copy. |
INLINE Sequence< Key, Alloc >& gum::Sequence< Key, Alloc >::operator= | ( | const Sequence< Key, OtherAlloc > & | aSeq | ) |
Definition at line 1113 of file sequence_tpl.h.
INLINE Sequence< Key, Alloc > & gum::Sequence< Key, Alloc >::operator= | ( | Sequence< Key, Alloc > && | aSeq | ) |
Move operator.
aSeq | The sequence to move. |
Definition at line 1120 of file sequence_tpl.h.
|
inherited |
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.
|
inherited |
Definition at line 956 of file sequence_tpl.h.
|
inherited |
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.
|
inherited |
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.
|
inherited |
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.
|
inherited |
Returns an unsafe rbegin iterator.
Definition at line 644 of file sequence_tpl.h.
|
inherited |
Returns a safe rbegin iterator.
Definition at line 616 of file sequence_tpl.h.
|
noexceptinherited |
Returns the unsafe rend iterator.
Definition at line 653 of file sequence_tpl.h.
|
noexceptinherited |
Returns the safe rend iterator.
Definition at line 625 of file sequence_tpl.h.
|
inherited |
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.
|
inherited |
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.
|
inherited |
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.
|
noexceptinherited |
Returns the size of the sequence.
Definition at line 37 of file sequence_tpl.h.
|
inherited |
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.
|
inherited |
Displays the content of the sequence.
Definition at line 552 of file sequence_tpl.h.