Represents a sparse vector, indexed by type Index and storing values of type Value.
More...
#include <sparse_vector.h>
|
using | pair_type = std::pair< Index, Value > |
|
using | container_type = std::vector< pair_type > |
|
using | iterator = typename container_type::iterator |
|
using | const_iterator = typename container_type::const_iterator |
|
|
| sparse_vector ()=default |
| Creates an empty sparse_vector.
|
|
| sparse_vector (uint64_t size) |
| Creates a sparse vector with size elements. More...
|
|
template<class Iter > |
| sparse_vector (Iter begin, Iter end) |
| Creates a sparse vector from a pair of iterators of pairs. More...
|
|
Value & | operator[] (const Index &index) |
| Gets the value associated with a given index in the vector, adding it with a value-initialized Value if not present. More...
|
|
Value | at (const Index &index) const |
| Gets the value associated with a given index in the vector. More...
|
|
const_iterator | find (const Index &index) const |
|
template<class... Ts> |
void | emplace_back (Ts &&...ts) |
| Adds a new element to the vector, placing it at the back. More...
|
|
void | reserve (uint64_t size) |
| Reserves space for elements. More...
|
|
void | clear () |
| Empties the vector.
|
|
void | shrink_to_fit () |
| Optimises the memory usage of the vector.
|
|
void | condense () |
| Condenses the vector to include only non-zero (value initialized) entries.
|
|
uint64_t | size () const |
|
bool | empty () const |
|
const container_type & | contents () const |
|
void | contents (container_type cont) |
|
iterator | begin () |
|
const_iterator | begin () const |
|
const_iterator | cbegin () const |
|
iterator | end () |
|
const_iterator | end () const |
|
const_iterator | cend () const |
|
|
container_type | storage_ |
| Internal storage for the sparse vector: a sorted vector of pairs.
|
|
template<class Index, class Value>
class meta::util::sparse_vector< Index, Value >
Represents a sparse vector, indexed by type Index and storing values of type Value.
This stores the elements in the vector in sorted order by the Index type.
template<class Index , class Value >
Creates a sparse vector with size elements.
- Parameters
-
size | The number of elements in the new sparse vector. |
template<class Index , class Value >
template<class Iter >
Creates a sparse vector from a pair of iterators of pairs.
- Parameters
-
begin | The iterator to the beginning of the sequence |
end | The iterator to the end of the sequence |
template<class Index, class Value >
Gets the value associated with a given index in the vector, adding it with a value-initialized Value if not present.
- Parameters
-
index | The index of the sparse vector to access |
- Returns
- a reference to the value associated with that index into the vector
template<class Index, class Value >
Gets the value associated with a given index in the vector.
If not present, this will return a value-initialized Value and will NOT modify the vector.
- Parameters
-
index | The index of the sparse vector to access |
- Returns
- the value associated with that index into the vector, or a value-initialized Value if there is none
template<class Index, class Value >
- Parameters
-
index | The index of the sparse vector to search for |
- Returns
- an iterator to that position, or the end iterator if it does not exist
template<class Index , class Value >
template<class... Ts>
Adds a new element to the vector, placing it at the back.
This assumes that you are adding elements in sorted order by Index—otherwise, the behavior of the vector afterwards is undefined.
- Parameters
-
ts | The arguments to forward to the pair constructor of the new element |
template<class Index , class Value >
Reserves space for elements.
- Parameters
-
size | The number of elements to reserve space for |
template<class Index , class Value >
- Returns
- the number of non-zero elements in the vector
template<class Index , class Value >
- Returns
- whether the vector is empty
template<class Index , class Value >
- Returns
- the contents of the vector
template<class Index , class Value >
- Parameters
-
cont | The new contents of the vector |
template<class Index , class Value >
- Returns
- an iterator to the beginning of the vector
template<class Index , class Value >
- Returns
- a const_iterator to the beginning of the vector
template<class Index , class Value >
- Returns
- a const_iterator to the beginning of the vector
template<class Index , class Value >
- Returns
- an iterator to the end of the vector
template<class Index , class Value >
- Returns
- a const_iterator to the end of the vector
template<class Index , class Value >
- Returns
- a const_iterator to the end of the vector
The documentation for this class was generated from the following files: