Sequences¶
template<typename T, typename... Properties>
using Sequence = Store<sequence<T>, Properties...>; // written out as Store<sequence<T>, ...> in code
-
class Sequence¶
A sequence:
Store<sequence<T>, Properties...>. The nameSequencestands for the resolved Store type on this page.
A sequence identifies its elements by position: positions are 0..n-1.
With sorted it keeps its elements in order and takes insert instead of push_back.
Request |
Representation |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Template parameters¶
TAny type;
orderablewithsorted. A Store as element is a row (Rows: Stores as values and elements).PWhat addresses the positions,
sequence<T, P>:std::size_tby default, or an index (urd::index<U>, anyindexablekey).Store<sequence<Node, index<Vertex>>>is a sequence parallel to the vertices another Store numbers:operator[]andattake a vertex’s index,positiongives one; it holds an element at every position below its size (no presence, unlike adensemap), and grows bypush_backandresizeas any sequence.
Member types¶
value_type is T; iterator and reference are the representation’s and are mutable where the
elements change in place: a sequence that is not frozen (a monotone one included: it only never removes), not
a multiset (which places elements by value), and not rows handed out as views.
Member functions¶
Construction, capacity (size, empty, reserve), iterators (begin, end, rbegin, rend) and
comparison (==, <=>) are as for Sets.
Element access¶
-
reference operator[](P pos)¶
-
const_reference operator[](P pos) const¶
-
reference at(P pos)¶
-
const_reference at(P pos) const¶
-
reference front()¶
-
reference back()¶
-
P position(const_iterator it) const¶
Pisstd::size_tbut in asequence<T, P>;atthrowsstd::out_of_rangepast the end and for what is no index (index<U>(), none).position(end())is the position after the last.
-
auto data()¶
A pointer to the elements, with
contiguous.
Modifiers¶
Growable (not frozen, not fixed_shape):
-
void push_back(const value_type &element)¶
-
void push_back(value_type &&element)¶
-
template<typename ...Args>
reference emplace_back(Args&&... args)¶ Sequences (the
appendingfacet). The new element, changeable in place where the elements are.
-
iterator insert(const value_type &element)¶
-
template<typename ...Args>
iterator emplace(Args&&... args)¶ Multisets (the
insertionfacet): into place, by value.
-
iterator insert(const_iterator pos, const value_type &element)¶
-
template<typename ...Args>
iterator emplace(const_iterator pos, Args&&... args)¶ Sequences, at a position (not
monotone).
Shrinkable (neither frozen nor monotone; monotone_until_clear keeps clear only):
-
iterator erase(const_iterator pos)¶
-
iterator erase(const_iterator first, const_iterator last)¶
-
void pop_back()¶
-
void clear()¶
Shape (fixed_shape)¶
-
explicit Sequence(const row_lengths &lengths)¶
Rows of these lengths, empty: a fixed-shape Store’s only shape. Rows of rows take a vector of row lengths per row, at any depth. With
nonempty, at least one row (a row of length 0 is a row), asserted.
-
void reset()¶
Every element back to its default, every bit unset; with
proportional_clear, in the rows handed out to change since the last reset only.
Complexity¶
Representation |
ordered lookup |
access |
iterate |
lookup |
insert |
erase |
clear |
memory |
holds |
|---|---|---|---|---|---|---|---|---|---|
|
— |
O(1) |
O(n) |
— |
O(1)* |
O(n) |
O(n) |
O(n), 1.5 words |
one array; retains |
|
O(log n) |
O(1) |
O(n) |
O(log n) |
O(n) |
O(n) |
O(n) |
O(n), 1.5 words |
n elements in one array; retains |
|
— |
O(1) |
O(n) |
— |
O(1)* |
O(1) |
O(n) |
O(n), 1.5 words |
doubling segments; stable references |
|
— |
O(1) |
O(n) |
— |
O(1)* |
O(1) |
O(n) |
O(n), 1.6 words |
doubling segments; stable references; appends from threads |
|
— |
O(1) |
O(n) |
— |
O(1)* |
O(1) |
O(n) |
O(n), 4 words |
rows kept with their storage |
|
— |
O(1) |
O(n) |
— |
O(r) |
O(n) |
O(n) |
O(n), 1.2 words |
one offsets array per level |
|
— |
O(1) |
O(n) |
— |
— |
— |
— |
O(n), 1.2 words |
one offsets array per level |
|
— |
O(1) |
O(n) |
— |
— |
— |
— |
O(n), 1.3 words |
one array, + the rows handed out to change |
* amortized, ~ expected; n elements, U the key range, r a row’s length, k a delta’s changes. Memory is the heap it holds (urd::memory_usage): what it grows in, and per element (or key, or slot) at most so many words, each the size of an element and at least a machine word. The declared costs; what they measure to is in Benchmarks.
Example¶
using Log = Store<sequence<Event>, monotone>; // only grows
using Rows = Store<sequence<Store<sequence<int>, frozen>>>; // compressed rows: one array, one of offsets
auto rows = Rows { { 1, 2, 3 }, { 4 } };
std::span<const int> first = rows[0];
using Bits = Store<sequence<Store<set<Vertex>, dense>>, fixed_shape>; // a bit matrix
auto bits = Bits(row_lengths { 8, 8, 8 });
bits[1].insert(Vertex { 3 });