Sux
|
#include <Vector.hpp>
Public Member Functions | |
Vector ()=default | |
Vector (size_t length) | |
Vector (const T *data, size_t length) | |
~Vector () | |
Vector (const Vector &)=delete | |
Vector & | operator= (const Vector &)=delete |
Vector (Vector< T, AT > &&oth) | |
Vector< T, AT > & | operator= (Vector< T, AT > &&oth) |
void | trim (size_t capacity) |
void | trimToFit () |
void | reserve (size_t capacity) |
void | grow (size_t capacity) |
void | resize (size_t size) |
void | size (size_t size) |
void | pushBack (T elem) |
T | popBack () |
T * | operator& () const |
const T & | operator[] (size_t i) const |
T & | operator[] (size_t i) |
size_t | size () const |
size_t | capacity () const |
size_t | bitCount () const |
Public Member Functions inherited from sux::util::Expandable | |
void | trimToFit () |
Static Public Attributes | |
static constexpr int | PROT = PROT_READ | PROT_WRITE |
static constexpr int | FLAGS = MAP_PRIVATE | MAP_ANONYMOUS | (AT == FORCEHUGEPAGE ? MAP_HUGETLB : 0) |
Friends | |
void | swap (Vector< T, AT > &first, Vector< T, AT > &second) noexcept |
std::ostream & | operator<< (std::ostream &os, const Vector< T, AT > &vector) |
std::istream & | operator>> (std::istream &is, Vector< T, AT > &vector) |
An expandable vector with settable type of memory allocation.
Instances of this class have a behavior similar to std::vector. However, the strategy used for allocation memory can be selected. Moreover, the class is just a thin wrapper around a backing array: in particular, there are no bound checks.
Once enough capacity has been allocated through reserve(size_t), the operator operator&() will return a pointer to the backing array and the allocated space can be used directly, if necessary.
This class implements the standard <<
and >>
operators for simple serialization and deserialization.
T | the data type of an element. |
AT | a type of memory allocation out of AllocType. |
|
default |
|
inlineexplicit |
|
inlineexplicit |
|
inline |
|
delete |
|
inline |
|
inline |
Returns the number of bits used by this vector.
|
inline |
Returns the number of elements that this vector can hold currently without increasing its capacity.
|
inlinevirtual |
Enlarges the backing array to that it can contain a given number of elements, plus possibly extra space.
If the current capacity is sufficient, nothing happens. Otherwise, the backing is enlarged to the maximum between the provided capacity and 50% more than the current capacity.
capacity | the desired new capacity. |
Implements sux::util::Expandable.
|
inline |
Returns a pointer at the start of the backing array.
|
delete |
|
inline |
|
inline |
Returns the given element of the vector.
|
inline |
Returns the given element of the vector.
|
inline |
Pops the element at the end of this vector.
The last element of this vector is removed and returned.
|
inline |
Adds a given element at the end of this vector.
elem | an element. |
|
inlinevirtual |
Enlarges the backing array to that it can contain a given number of elements.
If the current capacity is sufficient, nothing happens. Otherwise, the backing is enlarged to the provided capacity.
capacity | the desired new capacity. |
Implements sux::util::Expandable.
|
inlinevirtual |
Changes the vector size to the given value.
If the argument is smaller than or equal to the current size, the backing array is unmodified. Otherwise, the backing array is enlarged to the given size using grow(). New elements are initialized to zero.
size | the desired new size. |
Implements sux::util::Expandable.
|
inlinevirtual |
Returns the number of elements in this vector.
Implements sux::util::Expandable.
|
inlinevirtual |
Changes the vector size and capacity to the given value.
Both size and capacity are set to the provided size. If necessary, new elements are initialized to zero.
size | the desired new size. |
Implements sux::util::Expandable.
|
inlinevirtual |
Trim the the memory allocated so that it holds at most the given number of elements.
capacity | the new desired capacity. |
Implements sux::util::Expandable.
|
inline |
Trim the the memory allocated so that it holds exactly size() elements.
|
friend |
|
friend |
|
friend |
|
staticconstexpr |
|
staticconstexpr |