Vowpal Wabbit
|
v_array is a container type that makes use of realloc for efficiency. However, it is only safe to use trivially copyable types, as std::realloc may do a memcpy if a new piece of memory must be allocated. More...
#include <v_array.h>
Public Types | |
using | value_type = T |
using | reference = value_type & |
using | const_reference = const value_type & |
using | pointer = value_type * |
using | const_pointer = const value_type * |
using | iterator = value_type * |
using | const_iterator = const value_type * |
Public Member Functions | |
pointer | data () noexcept |
const_pointer | data () const noexcept |
iterator | begin () noexcept |
iterator | end () noexcept |
const_iterator | begin () const noexcept |
const_iterator | end () const noexcept |
const_iterator | cbegin () const noexcept |
const_iterator | cend () const noexcept |
v_array () noexcept | |
~v_array () | |
v_array (v_array< T > &&other) noexcept | |
v_array & | operator= (v_array< T > &&other) noexcept |
v_array (const v_array< T > &other) | |
v_array & | operator= (const v_array< T > &other) |
T & | back () |
const T & | back () const |
void | pop_back () |
Remove the last element from the container. If container is empty then this is undefined behavior. More... | |
bool | empty () const |
T & | operator[] (size_t i) const |
size_t | size () const |
size_t | capacity () const |
void | resize_but_with_stl_behavior (size_t length) |
Change the size of the container. More... | |
void | resize (size_t length) |
void | shrink_to_fit () |
Shrink the underlying buffer to just be large enough to hold the current elements. More... | |
void | reserve (size_t length) |
Reserve enough space for the specified number of elements. If the given size is less than the current capacity this call will do nothing. More... | |
void | clear_noshrink () |
void | clear () |
Clear all elements from container. Additionally keeps track of an erase count and when it reaches a certain threshold it will also shrink the underlying buffer. More... | |
iterator | erase (iterator it) |
Erase item at the given iterator. More... | |
iterator | erase (iterator first, iterator last) |
Erase items from first to end. [first, end) More... | |
iterator | insert (iterator it, const T &elem) |
Insert item into v_array directly after position. More... | |
iterator | insert (iterator it, T &&elem) |
Insert item into v_array directly after position. More... | |
template<class InputIt > | |
void | insert (iterator it, InputIt first, InputIt last) |
Insert the range (first, last] pointed to by first and last into this container at position it. More... | |
void | push_back (const T &new_ele) |
Add new element to end of container. More... | |
void | push_back_unchecked (const T &new_ele) |
Does not check if the container has the capacity for the new element. UB if size() == capacity(), or if container has just been default constructed as the internal buffers have not been allocated until an item has been inserted. More... | |
template<class... Args> | |
void | emplace_back (Args &&... args) |
Friends | |
std::ostream & | operator<< (std::ostream &os, const v_array< T > &v) |
v_array is a container type that makes use of realloc for efficiency. However, it is only safe to use trivially copyable types, as std::realloc may do a memcpy if a new piece of memory must be allocated.
T | Element type |
using VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::const_iterator = const value_type* |
using VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::const_pointer = const value_type* |
using VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::const_reference = const value_type& |
using VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::iterator = value_type* |
using VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::pointer = value_type* |
using VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::reference = value_type& |
using VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::value_type = T |
|
inlinenoexcept |
|
inline |
|
inlinenoexcept |
|
inline |
|
inline |
|
inline |
|
inlinenoexcept |
|
inlinenoexcept |
|
inline |
|
inlinenoexcept |
|
inlinenoexcept |
|
inline |
Clear all elements from container. Additionally keeps track of an erase count and when it reaches a certain threshold it will also shrink the underlying buffer.
|
inline |
|
inlinenoexcept |
|
inlinenoexcept |
|
inline |
|
inline |
|
inlinenoexcept |
|
inlinenoexcept |
|
inline |
Erase items from first to end. [first, end)
first | Iterator to begin erasing at. UB if it is nullptr or out of bounds of the v_array |
last | Iterator to end erasing at. UB if it is nullptr or out of bounds of the v_array |
|
inline |
|
inline |
|
inline |
Insert the range (first, last] pointed to by first and last into this container at position it.
InputIt | Iterator type of input |
it | Iterator to insert at. May be end(). UB if outside bounds. |
first | iterator to copy from |
last | iterator to copy to, but not including |
|
inline |
|
inline |
|
inlinenoexcept |
|
inline |
|
inline |
Remove the last element from the container. If container is empty then this is undefined behavior.
|
inline |
Add new element to end of container.
new_ele |
|
inline |
Does not check if the container has the capacity for the new element. UB if size() == capacity(), or if container has just been default constructed as the internal buffers have not been allocated until an item has been inserted.
new_ele | Element to insert |
|
inline |
Reserve enough space for the specified number of elements. If the given size is less than the current capacity this call will do nothing.
length | Ensure the underlying buffer can fit at least this many elements. |
|
inline |
|
inline |
Change the size of the container.
length | Will default construct new elements if length is larger than current or remove elements if it is smaller. |
|
inline |
Shrink the underlying buffer to just be large enough to hold the current elements.
|
inline |
|
friend |