lxgui
|
Sorted std::vector wrapper. This class is a light alternative to std::set. Inspired from: [1] www.lafstern.org/matt/col1.pdf. More...
#include <utils_sorted_vector.hpp>
Public Types | |
using | iterator = typename base::iterator |
using | const_iterator = typename base::const_iterator |
using | reverse_iterator = typename base::reverse_iterator |
using | const_reverse_iterator = typename base::const_reverse_iterator |
Public Member Functions | |
sorted_vector ()=default | |
Default constructor. Creates an empty vector. | |
sorted_vector (const sorted_vector &s)=default | |
Copy another vector into this one. | |
sorted_vector (sorted_vector &&s)=default | |
Move another sorted_vector into this one. The other vector is left empty in the process, and all its content is transfered into this new one. | |
sorted_vector & | operator= (const sorted_vector &s)=default |
Copy another sorted_vector into this one. | |
sorted_vector & | operator= (sorted_vector &&s)=default |
Move another vector into this one. The other vector is left empty in the process, and all its content is transfered into this new one. | |
sorted_vector (const base &s) | |
Copy a pre-built vector into this one. The provided vector must be sorted, and shall not contain any duplicate value. | |
sorted_vector (base &&s) | |
Move a pre-built vector into this one. The provided vector must be sorted, and shall not contain any duplicate value. It is left empty in the process, and all its content is transfered into this new sorted_vector. | |
sorted_vector (const Cmp &c) | |
Default constructor, with comparator. Creates an empty vector and sets the comparator function. | |
sorted_vector (std::initializer_list< T > l) | |
Write an initializer list into this vector. The list need not be sorted. | |
Cmp & | comparator () |
Return the comparator object. | |
const Cmp & | comparator () const |
Return the comparator object. | |
template<typename U > | |
std::pair< iterator, bool > | insert (U &&t) |
Insert the provided object in the vector, only if no object exists with the same key. | |
template<typename U > | |
iterator | insert_or_assign (U &&t) |
Insert the provided object in the vector. | |
iterator | erase (iterator iter) |
Erase an element from this vector. | |
iterator | erase (iterator first, iterator last) |
Erase a range from this vector. | |
template<typename Key > | |
iterator | erase (const Key &k) |
Erase an element from this vector by its key. The key can be a copy of the element itself, or any other object that is supported by the chosen comparison function. If no object is found with that key, this function does nothing. | |
template<typename Key > | |
iterator | find (const Key &k) |
Find an object in this vector by its key. The key can be a copy of the element itself, or any other object that is supported by the chosen comparison function. If no element is found, this function returns end(). | |
template<typename Key > | |
const_iterator | find (const Key &k) const |
Find an object in this vector by its key. The key can be a copy of the element itself, or any other object that is supported by the chosen comparison function. If no element is found, this function returns end(). | |
Sorted std::vector wrapper. This class is a light alternative to std::set. Inspired from: [1] www.lafstern.org/matt/col1.pdf.
The sorted vector achieves the same O(log(N)) look up complexity as std::set, but with a lower constant of proportionality thanks to the binary search algorithm (twice lower according to [1]). The fact that this container uses an std::vector internally also implies that it has the lowest possible memory usage.
On the other hand, it has worse insertion complexity (O(N), compared to the O(log(N)) of std::set). This drawback can be completely ignored if either:
The elements of this container are sorted according to the Cmp template argument, which defaults to std::less<T> (i.e. the elements are sorted using operator<()). One can provide a custom comparison functor if std::less is not desirable. Using a custom comparison functor can also allow to find elements by keys instead of their own value. For example, if T is
then one can use the following comparison functor:
and use an integer as the key to find elements in the container
Definition at line 69 of file utils_sorted_vector.hpp.
using lxgui::utils::sorted_vector< T, Cmp >::const_iterator = typename base::const_iterator |
Definition at line 75 of file utils_sorted_vector.hpp.
using lxgui::utils::sorted_vector< T, Cmp >::const_reverse_iterator = typename base::const_reverse_iterator |
Definition at line 77 of file utils_sorted_vector.hpp.
using lxgui::utils::sorted_vector< T, Cmp >::iterator = typename base::iterator |
Definition at line 74 of file utils_sorted_vector.hpp.
using lxgui::utils::sorted_vector< T, Cmp >::reverse_iterator = typename base::reverse_iterator |
Definition at line 76 of file utils_sorted_vector.hpp.
|
default |
Default constructor. Creates an empty vector.
|
default |
Copy another vector into this one.
|
default |
Move another sorted_vector into this one. The other vector is left empty in the process, and all its content is transfered into this new one.
|
inlineexplicit |
Copy a pre-built vector into this one. The provided vector must be sorted, and shall not contain any duplicate value.
Definition at line 109 of file utils_sorted_vector.hpp.
|
inlineexplicit |
Move a pre-built vector into this one. The provided vector must be sorted, and shall not contain any duplicate value. It is left empty in the process, and all its content is transfered into this new sorted_vector.
Definition at line 117 of file utils_sorted_vector.hpp.
|
inlineexplicit |
Default constructor, with comparator. Creates an empty vector and sets the comparator function.
Definition at line 123 of file utils_sorted_vector.hpp.
|
inline |
Write an initializer list into this vector. The list need not be sorted.
Definition at line 129 of file utils_sorted_vector.hpp.
|
inline |
Return the comparator object.
Definition at line 136 of file utils_sorted_vector.hpp.
|
inline |
Return the comparator object.
Definition at line 141 of file utils_sorted_vector.hpp.
|
inline |
Erase an element from this vector by its key. The key can be a copy of the element itself, or any other object that is supported by the chosen comparison function. If no object is found with that key, this function does nothing.
Definition at line 195 of file utils_sorted_vector.hpp.
|
inline |
Erase a range from this vector.
Definition at line 184 of file utils_sorted_vector.hpp.
|
inline |
Erase an element from this vector.
Definition at line 179 of file utils_sorted_vector.hpp.
|
inline |
Find an object in this vector by its key. The key can be a copy of the element itself, or any other object that is supported by the chosen comparison function. If no element is found, this function returns end().
Definition at line 210 of file utils_sorted_vector.hpp.
|
inline |
Find an object in this vector by its key. The key can be a copy of the element itself, or any other object that is supported by the chosen comparison function. If no element is found, this function returns end().
Definition at line 226 of file utils_sorted_vector.hpp.
|
inline |
Insert the provided object in the vector, only if no object exists with the same key.
Definition at line 152 of file utils_sorted_vector.hpp.
|
inline |
Insert the provided object in the vector.
Definition at line 171 of file utils_sorted_vector.hpp.
|
default |
Copy another sorted_vector into this one.
|
default |
Move another vector into this one. The other vector is left empty in the process, and all its content is transfered into this new one.