Vowpal Wabbit
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Friends | List of all members
VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type > Class Template Reference

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_arrayoperator= (v_array< T > &&other) noexcept
 
 v_array (const v_array< T > &other)
 
v_arrayoperator= (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)
 

Detailed Description

template<class T>
class VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >

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.

Template Parameters
TElement type

Member Typedef Documentation

◆ const_iterator

template<class T >
using VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::const_iterator = const value_type*

◆ const_pointer

template<class T >
using VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::const_pointer = const value_type*

◆ const_reference

template<class T >
using VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::const_reference = const value_type&

◆ iterator

template<class T >
using VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::iterator = value_type*

◆ pointer

template<class T >
using VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::pointer = value_type*

◆ reference

template<class T >
using VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::reference = value_type&

◆ value_type

template<class T >
using VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::value_type = T

Constructor & Destructor Documentation

◆ v_array() [1/3]

template<class T >
VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::v_array ( )
inlinenoexcept

◆ ~v_array()

template<class T >
VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::~v_array ( )
inline

◆ v_array() [2/3]

template<class T >
VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::v_array ( v_array< T > &&  other)
inlinenoexcept

◆ v_array() [3/3]

template<class T >
VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::v_array ( const v_array< T > &  other)
inline

Member Function Documentation

◆ back() [1/2]

template<class T >
T & VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::back ( )
inline

◆ back() [2/2]

template<class T >
const T & VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::back ( ) const
inline

◆ begin() [1/2]

template<class T >
const_iterator VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::begin ( ) const
inlinenoexcept

◆ begin() [2/2]

template<class T >
iterator VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::begin ( )
inlinenoexcept

◆ capacity()

template<class T >
size_t VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::capacity ( ) const
inline

◆ cbegin()

template<class T >
const_iterator VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::cbegin ( ) const
inlinenoexcept

◆ cend()

template<class T >
const_iterator VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::cend ( ) const
inlinenoexcept

◆ clear()

template<class T >
void VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::clear ( )
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.

◆ clear_noshrink()

template<class T >
void VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::clear_noshrink ( )
inline

◆ data() [1/2]

template<class T >
const_pointer VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::data ( ) const
inlinenoexcept

◆ data() [2/2]

template<class T >
pointer VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::data ( )
inlinenoexcept

◆ emplace_back()

template<class T >
template<class... Args>
void VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::emplace_back ( Args &&...  args)
inline

◆ empty()

template<class T >
bool VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::empty ( ) const
inline

◆ end() [1/2]

template<class T >
const_iterator VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::end ( ) const
inlinenoexcept

◆ end() [2/2]

template<class T >
iterator VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::end ( )
inlinenoexcept

◆ erase() [1/2]

template<class T >
iterator VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::erase ( iterator  first,
iterator  last 
)
inline

Erase items from first to end. [first, end)

Parameters
firstIterator to begin erasing at. UB if it is nullptr or out of bounds of the v_array
lastIterator to end erasing at. UB if it is nullptr or out of bounds of the v_array
Returns
Iterator to item immediately following the erased elements. May be equal to end()
Note
Invalidates iterators

◆ erase() [2/2]

template<class T >
iterator VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::erase ( iterator  it)
inline

Erase item at the given iterator.

Parameters
itIterator to erase at. UB if it is nullptr or out of bounds of the v_array
Returns
Iterator to item immediately following the erased element. May be equal to end()
Note
Invalidates iterators

◆ insert() [1/3]

template<class T >
iterator VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::insert ( iterator  it,
const T &  elem 
)
inline

Insert item into v_array directly after position.

Parameters
itIterator to insert at. May be end(). UB if outside bounds.
elemElement to insert
Returns
Iterator to inserted item.
Note
Invalidates iterators

◆ insert() [2/3]

template<class T >
template<class InputIt >
void VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::insert ( iterator  it,
InputIt  first,
InputIt  last 
)
inline

Insert the range (first, last] pointed to by first and last into this container at position it.

Template Parameters
InputItIterator type of input
Parameters
itIterator to insert at. May be end(). UB if outside bounds.
firstiterator to copy from
lastiterator to copy to, but not including
Note
Invalidates iterators

◆ insert() [3/3]

template<class T >
iterator VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::insert ( iterator  it,
T &&  elem 
)
inline

Insert item into v_array directly after position.

Parameters
itIterator to insert at. May be end(). UB if outside bounds.
elemElement to insert
Returns
Iterator to inserted item.
Note
Invalidates iterators

◆ operator=() [1/2]

template<class T >
v_array & VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::operator= ( const v_array< T > &  other)
inline

◆ operator=() [2/2]

template<class T >
v_array & VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::operator= ( v_array< T > &&  other)
inlinenoexcept

◆ operator[]()

template<class T >
T & VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::operator[] ( size_t  i) const
inline

◆ pop_back()

template<class T >
void VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::pop_back ( )
inline

Remove the last element from the container. If container is empty then this is undefined behavior.

◆ push_back()

template<class T >
void VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::push_back ( const T &  new_ele)
inline

Add new element to end of container.

Parameters
new_ele

◆ push_back_unchecked()

template<class T >
void VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::push_back_unchecked ( const T &  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.

Parameters
new_eleElement to insert

◆ reserve()

template<class T >
void VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::reserve ( size_t  length)
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.

Parameters
lengthEnsure the underlying buffer can fit at least this many elements.

◆ resize()

template<class T >
void VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::resize ( size_t  length)
inline

◆ resize_but_with_stl_behavior()

template<class T >
void VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::resize_but_with_stl_behavior ( size_t  length)
inline

Change the size of the container.

Parameters
lengthWill default construct new elements if length is larger than current or remove elements if it is smaller.
Note
To be renamed to resize() in VW 9
Deprecated:
"Renamed to resize. resize_but_with_stl_behavior will be removed in VW 10."

◆ shrink_to_fit()

template<class T >
void VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::shrink_to_fit ( )
inline

Shrink the underlying buffer to just be large enough to hold the current elements.

◆ size()

template<class T >
size_t VW::v_array< T, typename std::enable_if< std::is_trivially_copyable< T >::value >::type >::size ( ) const
inline

Friends And Related Function Documentation

◆ operator<<

template<class T >
std::ostream & operator<< ( std::ostream &  os,
const v_array< T > &  v 
)
friend

The documentation for this class was generated from the following file: