Template Class ArraySequence

Class Documentation

template<class T>
class ArraySequence

a SEQUENCE realized with a vector that doubles when it is full

Public Types

using Item = T

the type of the items

using Pos = long

a position is an index, from -1 to n

using value_type = T
using size_type = std::size_t
using difference_type = std::ptrdiff_t
using reference = T&
using const_reference = const T&
using pointer = T*
using const_pointer = const T*
using iterator = T*
using const_iterator = const T*
using reverse_iterator = std::reverse_iterator<iterator>
using const_reverse_iterator = std::reverse_iterator<const_iterator>

Public Functions

ArraySequence(void)

the empty sequence, with no vector

ArraySequence(std::initializer_list<T> items)

the sequence of the given items, in their order

template<std::input_iterator I, std::sentinel_for<I> S>
ArraySequence(I first, S last)

the sequence of the items of [ first , last ), in their order

ArraySequence(const ArraySequence &other)
ArraySequence(ArraySequence &&other) noexcept

the items of other, which is left empty

ArraySequence &operator=(ArraySequence other) noexcept
bool empty(void) const
bool finished(Pos p) const

true if p is -1 or n

Pos head(void) const
Pos tail(void) const
Pos next(Pos p) const
Pre:

-1 <= p < n

Pos prev(Pos p) const
Pre:

0 <= p <= n

Pos insert(Pos p, const T &v)

puts v at index p, the items from index p moving one place on, which takes O( n - p ) time, O( 1 ) amortized at the end

Pre:

0 <= p <= n

Post:

one item more, v at index p, the others where they were before p and one place on from p (an audit)

Pos remove(Pos p)

removes the item at index p, the following ones moving one place back; a vector left a quarter full is halved

Pre:

0 <= p < n

Post:

one item less, the others where they were before p and one place back after it (an audit)

const T &read(Pos p) const
Pre:

0 <= p < n

void write(Pos p, const T &v)
Pre:

0 <= p < n

Post:

read( p ) is v, the other items unchanged (an audit)

Pos size(void) const

the number of items

Pos capacity(void) const

the size of the vector, which the analysis of the doubling is about

bool operator==(const ArraySequence &o) const

the same items in the same order

inline iterator begin(void)
inline iterator end(void)
inline const_iterator begin(void) const
inline const_iterator end(void) const
inline const_iterator cbegin(void) const
inline const_iterator cend(void) const
inline reverse_iterator rbegin(void)
inline reverse_iterator rend(void)
inline const_reverse_iterator rbegin(void) const
inline const_reverse_iterator rend(void) const
inline T *data(void)
inline const T *data(void) const
T &operator[](Pos i)
Pre:

0 <= i < n

const T &operator[](Pos i) const
void push_back(const T &v)

v at the end, for std::back_inserter