![]() |
aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
|
The generic class for storing (ordered) sequences of objects. More...
#include <agrum/base/core/sequence.h>
Public Types | |
| using | Implementation = SequenceImplementation< Key, std::is_scalar< Key >::value > |
| The gum::Sequence implementation. | |
| 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 | |
| INLINE void | emplace (Args &&... args) |
Constructors / Destructors | |
| Sequence (Size size_param=HashTableConst::default_size) | |
| Default constructor. | |
| Sequence (std::initializer_list< Key > list) | |
| Initializer list constructor. | |
| Sequence (const Sequence< Key > &aSeq) | |
| Copy constructor. | |
| Sequence (Sequence< Key > &&aSeq) | |
| Move constructor. | |
| ~Sequence () noexcept | |
| Class destructor. | |
Operators | |
| Sequence< Key > & | operator= (const Sequence< Key > &aSeq) |
| Copy operator. | |
| Sequence< Key > & | operator= (Sequence< Key > &&aSeq) |
| Move operator. | |
Accessors / Modifiers | |
| Set< Key > | diffSet (const Sequence< Key > &seq) const |
| Difference between two sequences as a Set<Key> = this \ seq. | |
Iterators | |
| iterator_safe | beginSafe () const |
| Returns a safe begin iterator. | |
| iterator_safe | rbeginSafe () const |
| Returns a safe rbegin iterator. | |
| const iterator_safe & | endSafe () const noexcept |
| Returns the safe end iterator. | |
| const iterator_safe & | rendSafe () const noexcept |
| Returns the safe rend iterator. | |
| iterator | begin () const |
| Returns an unsafe begin iterator. | |
| iterator | rbegin () const |
| Returns an unsafe rbegin iterator. | |
| const iterator & | end () const noexcept |
| Returns the unsafe end iterator. | |
| const iterator & | rend () 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. | |
| 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. | |
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. | |
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. |
Definition at line 972 of file sequence.h.
| using gum::Sequence< Key >::const_iterator = SequenceIterator< Key > |
Types for STL compliance.
Definition at line 984 of file sequence.h.
| using gum::Sequence< Key >::const_iterator_safe = SequenceIteratorSafe< Key > |
Types for STL compliance.
Definition at line 986 of file sequence.h.
| using gum::Sequence< Key >::const_pointer = const Key* |
Types for STL compliance.
Definition at line 980 of file sequence.h.
| using gum::Sequence< Key >::const_reference = const Key& |
Types for STL compliance.
Definition at line 978 of file sequence.h.
| using gum::Sequence< Key >::difference_type = std::ptrdiff_t |
Types for STL compliance.
Definition at line 982 of file sequence.h.
| using gum::Sequence< Key >::Implementation = SequenceImplementation< Key, std::is_scalar< Key >::value > |
The gum::Sequence implementation.
Definition at line 990 of file sequence.h.
| using gum::Sequence< Key >::iterator = SequenceIterator< Key > |
Types for STL compliance.
Definition at line 983 of file sequence.h.
| using gum::Sequence< Key >::iterator_safe = SequenceIteratorSafe< Key > |
Types for STL compliance.
Definition at line 985 of file sequence.h.
| using gum::Sequence< Key >::pointer = Key* |
Types for STL compliance.
Definition at line 979 of file sequence.h.
| using gum::Sequence< Key >::reference = Key& |
Types for STL compliance.
Definition at line 977 of file sequence.h.
| using gum::Sequence< Key >::size_type = std::size_t |
Types for STL compliance.
Definition at line 981 of file sequence.h.
| using gum::Sequence< Key >::value_type = Key |
Types for STL compliance.
Definition at line 976 of file sequence.h.
| INLINE gum::Sequence< Key >::Sequence | ( | Size | size_param = HashTableConst::default_size | ) |
Default constructor.
| size_param | The intial size of the gum::SequenceImplementation. |
Definition at line 992 of file sequence_tpl.h.
References Sequence(), and gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::SequenceImplementation().
Referenced by Sequence(), Sequence(), Sequence(), and ~Sequence().
| INLINE gum::Sequence< Key >::Sequence | ( | std::initializer_list< Key > | list | ) |
Initializer list constructor.
| list | The initializer list. |
Definition at line 999 of file sequence_tpl.h.
References gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::SequenceImplementation().
| INLINE gum::Sequence< Key >::Sequence | ( | const Sequence< Key > & | aSeq | ) |
Copy constructor.
| aSeq | The sequence the elements of which will be copied. |
Definition at line 1007 of file sequence_tpl.h.
References Sequence(), gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::SequenceImplementation(), and gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::Sequence< Key >.
| INLINE gum::Sequence< Key >::Sequence | ( | Sequence< Key > && | aSeq | ) |
Move constructor.
| aSeq | The gum::Sequence to move/ |
Definition at line 1015 of file sequence_tpl.h.
References Sequence(), gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::SequenceImplementation(), and gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::Sequence< Key >.
|
noexcept |
Class destructor.
Definition at line 1023 of file sequence_tpl.h.
References Sequence().
|
privateinherited |
Clears the current sequence and fill it with copies the element of aSeq.
| aSeq | The gum::SequenceImplementation to copy. |
References SequenceImplementation(), and _copy_().
Referenced by _copy_().
|
privateinherited |
Insert an element at the end of the sequence.
| bucket | The bucket holing the store to insert. |
References gum::SequenceImplementation< Key, Gen >::SequenceImplementation(), SequenceImplementation(), gum::SequenceImplementation< Key, Gen >::~SequenceImplementation(), gum::SequenceImplementation< Key, Gen >::_copy_(), _end_safe_, _h_, gum::SequenceImplementation< Key, Gen >::_insert_(), _insert_(), _rend_safe_, gum::SequenceImplementation< Key, Gen >::_update_end_(), _v_, gum::SequenceImplementation< Key, Gen >::atPos(), gum::SequenceImplementation< Key, Gen >::back(), gum::SequenceImplementation< Key, Gen >::begin(), gum::SequenceImplementation< Key, Gen >::beginSafe(), gum::SequenceImplementation< Key, Gen >::clear(), gum::HashTableConst::default_size, gum::SequenceImplementation< Key, Gen >::emplace(), gum::SequenceImplementation< Key, Gen >::empty(), gum::SequenceImplementation< Key, Gen >::end(), gum::SequenceImplementation< Key, Gen >::endSafe(), gum::SequenceImplementation< Key, Gen >::erase(), gum::SequenceImplementation< Key, Gen >::exists(), gum::SequenceImplementation< Key, Gen >::front(), gum::SequenceImplementation< Key, Gen >::insert(), gum::SequenceImplementation< Key, Gen >::operator!=(), gum::SequenceImplementation< Key, Gen >::operator<<(), gum::SequenceImplementation< Key, Gen >::operator=(), gum::SequenceImplementation< Key, Gen >::operator==(), gum::SequenceImplementation< Key, Gen >::operator>>(), gum::SequenceImplementation< Key, Gen >::operator[](), gum::SequenceImplementation< Key, Gen >::pos(), gum::SequenceImplementation< Key, Gen >::rbegin(), gum::SequenceImplementation< Key, Gen >::rbeginSafe(), gum::SequenceImplementation< Key, Gen >::rend(), gum::SequenceImplementation< Key, Gen >::rendSafe(), gum::SequenceImplementation< Key, Gen >::resize(), SequenceIteratorSafe< Key >, gum::SequenceImplementation< Key, Gen >::setAtPos(), gum::SequenceImplementation< Key, Gen >::size(), gum::SequenceImplementation< Key, Gen >::swap(), and gum::SequenceImplementation< Key, Gen >::toString().
Referenced by _insert_().
|
privatenoexceptinherited |
A method to update the end iterator after changes in the sequence.
References _update_end_().
Referenced by _update_end_(), and emplace().
|
inherited |
Returns the object at the pos i.
| i | The position of the element to return. |
| NotFound | Raised if the element does not exist. |
References atPos().
Referenced by atPos().
|
inherited |
Returns the last element of the sequence.
| NotFound | Raised if the sequence is empty. |
References back().
Referenced by gum::prm::StructuredInference< GUM_SCALAR >::_removeBarrenNodes_(), and back().
|
inherited |
Returns an unsafe begin iterator.
References begin().
Referenced by gum::InfluenceDiagramGenerator< GUM_SCALAR >::_checkTemporalOrder_(), begin(), gum::InfluenceDiagram< GUM_SCALAR >::decisionOrderExists(), and gum::Sequence< Key >::diffSet().
|
inherited |
Returns a safe begin iterator.
References beginSafe().
Referenced by beginSafe().
|
inherited |
| Set< Key > gum::Sequence< Key >::diffSet | ( | const Sequence< Key > & | seq | ) | const |
Difference between two sequences as a Set<Key> = this \ seq.
| seq | The gum::Sequence to substract of this. |
Definition at line 1044 of file sequence_tpl.h.
References gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::begin(), gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::end(), gum::SequenceImplementation< Key, Gen >::exists(), and gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::Sequence< Key >.
|
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. |
References emplace().
Referenced by emplace().
|
inherited |
Definition at line 388 of file sequence_tpl.h.
References _h_, _update_end_(), and _v_.
|
noexceptinherited |
|
noexceptinherited |
Returns the unsafe end iterator.
References end().
Referenced by gum::InfluenceDiagramGenerator< GUM_SCALAR >::_checkTemporalOrder_(), gum::InfluenceDiagram< GUM_SCALAR >::decisionOrderExists(), gum::Sequence< Key >::diffSet(), and end().
|
noexceptinherited |
|
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. |
References erase().
|
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. |
References erase().
Referenced by gum::prm::StructuredInference< GUM_SCALAR >::_removeBarrenNodes_(), erase(), and erase().
|
inherited |
Check the existence of k in the sequence.
The complexity is \(o(1)\).
| k | The key to check for existence. |
References exists().
Referenced by gum::BarrenNodesFinder::barrenNodes(), and exists().
|
inherited |
|
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. |
References insert().
Referenced by gum::prm::StructuredInference< GUM_SCALAR >::_removeBarrenNodes_(), gum::BarrenNodesFinder::barrenNodes(), gum::InfluenceDiagram< GUM_SCALAR >::getChildrenDecision_(), insert(), and insert().
|
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. |
References insert().
|
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.
| k | The other gum::SequenceImplementation. |
Returns true if both gum::SequenceImplementation are not equal.
References SequenceImplementation().
|
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. |
References SequenceImplementation().
|
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. |
| INLINE Sequence< Key > & gum::Sequence< Key >::operator= | ( | const Sequence< Key > & | aSeq | ) |
Copy operator.
| aSeq | The sequence to copy. |
Definition at line 1030 of file sequence_tpl.h.
References gum::SequenceImplementation< Key, Gen >::operator=(), and gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::Sequence< Key >.
| INLINE Sequence< Key > & gum::Sequence< Key >::operator= | ( | Sequence< Key > && | aSeq | ) |
Move operator.
| aSeq | The sequence to move. |
Definition at line 1037 of file sequence_tpl.h.
References gum::SequenceImplementation< Key, Gen >::operator=(), and gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::Sequence< Key >.
|
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.
| k | The other gum::SequenceImplementation. |
Returns true if both gum::SequenceImplementation are equal.
References SequenceImplementation().
|
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. |
References SequenceImplementation().
|
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. |
|
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. |
References pos().
Referenced by gum::learning::IBNLearner::learnDag_(), and pos().
|
inherited |
|
inherited |
Returns a safe rbegin iterator.
References rbeginSafe().
Referenced by rbeginSafe().
|
noexceptinherited |
|
noexceptinherited |
Returns the safe rend iterator.
References rendSafe().
Referenced by rendSafe().
|
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. |
References resize().
Referenced by resize().
|
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. |
References setAtPos().
Referenced by setAtPos(), and setAtPos().
|
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. |
References setAtPos().
|
noexceptinherited |
Returns the size of the sequence.
References size().
Referenced by gum::prm::StructuredInference< GUM_SCALAR >::_removeBarrenNodes_(), gum::BarrenNodesFinder::barrenNodes(), and size().
|
inherited |
|
inherited |
Displays the content of the sequence.
References toString().
Referenced by gum::ActionSet::operator<<, gum::ArgMaxSet< GUM_SCALAR_VAL, GUM_SCALAR_SEQ >::operator<<, and toString().
|
privateinherited |
Stores the end iterator for fast access.
Definition at line 498 of file sequence.h.
Referenced by _insert_().
|
privateinherited |
Keep track of the position of the element in v (for fast retrieval).
Definition at line 488 of file sequence.h.
Referenced by _insert_(), and emplace().
|
privateinherited |
Stores the rend iterator for fast access.
Definition at line 501 of file sequence.h.
Referenced by _insert_().
|
privateinherited |
The set of the elements stored into the sequence.
Definition at line 491 of file sequence.h.
Referenced by _insert_(), and emplace().