Lunchbox
1.4.0
|
STL-like vector implementation providing certain thread-safety guarantees. More...
#include <lfVector.h>
Public Member Functions | |
LFVector () | |
LFVector (const size_t n) | |
LFVector (const size_t n, const T &t) | |
LFVector (const LFVector &from) | |
template<int32_t fromSlots> | |
LFVector (const LFVector< T, fromSlots > &from) | |
~LFVector () | |
LFVector & | operator= (const LFVector &from) |
bool | operator== (const LFVector &rhs) const |
bool | operator!= (const LFVector &rhs) const |
bool | empty () const |
size_t | size () const |
T & | operator[] (size_t i) |
const T & | operator[] (size_t i) const |
T & | front () |
T & | back () |
const_iterator | begin () const |
const_iterator | end () const |
iterator | begin () |
iterator | end () |
void | expand (const size_t newSize, const T &item=T()) |
Resize the vector to at least the given size. | |
void | push_back (const T &item) |
Add an element to the vector. | |
void | pop_back () |
Remove the last element (STL version). | |
bool | pop_back (T &element) |
Remove the last element (atomic version). | |
iterator | erase (iterator pos) |
Remove an element. | |
iterator | erase (const T &element) |
Remove the last occurence of the given element. | |
void | clear () |
Clear the vector and all storage. | |
Public Types | |
typedef LFVectorIterator < LFVector< T >, T > | iterator |
Iterator over the vector elements. | |
typedef LFVectorIterator < const LFVector< T >, const T > | const_iterator |
Iterator over the const vector elements. |
STL-like vector implementation providing certain thread-safety guarantees.
All operations not modifying the vector size are lock-free and wait-free. All operations modifying the vector size are serialized using a spin lock. The interaction of operations is documented in the corresponding modify operation.
Undocumented methods behave like the STL implementation. The number of slots (default 32) sets the maximum elements the vector may hold to 2^nSlots-1. Each slot needs one pointer additional storage. Naturally it should never be set higher than 64.
Not all std::vector methods are implemented.
Definition at line 57 of file lfVector.h.
typedef LFVectorIterator< const LFVector< T >, const T > lunchbox::LFVector< T, nSlots >::const_iterator |
typedef LFVectorIterator< LFVector< T >, T > lunchbox::LFVector< T, nSlots >::iterator |
lunchbox::LFVector< T, nSlots >::LFVector | ( | ) | [inline] |
Definition at line 63 of file lfVector.h.
lunchbox::LFVector< T, nSlots >::LFVector | ( | const size_t | n | ) | [inline, explicit] |
Definition at line 66 of file lfVector.h.
References lunchbox::getIndexOfLastBit().
lunchbox::LFVector< T, nSlots >::LFVector | ( | const size_t | n, |
const T & | t | ||
) | [inline, explicit] |
Definition at line 76 of file lfVector.h.
References lunchbox::getIndexOfLastBit().
lunchbox::LFVector< T, nSlots >::LFVector | ( | const LFVector< T, nSlots > & | from | ) | [inline, explicit] |
Definition at line 95 of file lfVector.h.
lunchbox::LFVector< T, nSlots >::LFVector | ( | const LFVector< T, fromSlots > & | from | ) | [inline, explicit] |
Definition at line 100 of file lfVector.h.
lunchbox::LFVector< T, nSlots >::~LFVector | ( | ) | [inline] |
Definition at line 105 of file lfVector.h.
T& lunchbox::LFVector< T, nSlots >::back | ( | ) | [inline] |
Definition at line 204 of file lfVector.h.
References lunchbox::LFVector< T, nSlots >::empty().
Referenced by lunchbox::LFVector< T, nSlots >::pop_back().
LFVector< T, nSlots >::const_iterator lunchbox::LFVector< T, nSlots >::begin | ( | ) | const [inline] |
Definition at line 471 of file lfVector.h.
Referenced by lunchbox::LFVector< T, nSlots >::operator==().
LFVector< T, nSlots >::iterator lunchbox::LFVector< T, nSlots >::begin | ( | ) | [inline] |
Definition at line 483 of file lfVector.h.
void lunchbox::LFVector< T, nSlots >::clear | ( | ) | [inline] |
Clear the vector and all storage.
Thread-safe with other write operations. By nature not thread-safe with read operations.
Definition at line 375 of file lfVector.h.
bool lunchbox::LFVector< T, nSlots >::empty | ( | ) | const [inline] |
Definition at line 168 of file lfVector.h.
Referenced by lunchbox::LFVector< T, nSlots >::back(), and lunchbox::LFVector< T, nSlots >::front().
LFVector< T, nSlots >::const_iterator lunchbox::LFVector< T, nSlots >::end | ( | ) | const [inline] |
Definition at line 477 of file lfVector.h.
Referenced by lunchbox::LFVector< T, nSlots >::erase(), and lunchbox::LFVector< T, nSlots >::operator==().
LFVector< T, nSlots >::iterator lunchbox::LFVector< T, nSlots >::end | ( | ) | [inline] |
Definition at line 489 of file lfVector.h.
iterator lunchbox::LFVector< T, nSlots >::erase | ( | iterator | pos | ) | [inline] |
Remove an element.
A concurrent read on the item or any following item is not thread save. The vector's size is decremented first. Returns end() if the element can't be removed, i.e., the iterator is past end() or not for this vector.
pos | the element to remove |
Definition at line 317 of file lfVector.h.
References lunchbox::LFVector< T, nSlots >::end().
iterator lunchbox::LFVector< T, nSlots >::erase | ( | const T & | element | ) | [inline] |
Remove the last occurence of the given element.
A concurrent read on the item or any following item is not thread save. The vector's size is decremented first. Returns end() if the element can't be removed, i.e., the vector does not contain the element.
element | the element to remove |
Definition at line 346 of file lfVector.h.
References lunchbox::LFVector< T, nSlots >::end().
void lunchbox::LFVector< T, nSlots >::expand | ( | const size_t | newSize, |
const T & | item = T( ) |
||
) | [inline] |
Resize the vector to at least the given size.
In contrast to resize(), expand() only increases the size of the vector, allowing concurrent resize operations on the same vector. Completely thread-save with read operations. Existing end() iterators will keep pointing to the old end of the vector. The size is updated after all elements have been inserted, so size() followed by a read is thread-safe. In contrast to while( vector.size() < newSize ) vector.insert( item );
this method's operation is atomic with other writes.
newSize | the minimum new size. |
item | the element to insert. |
Definition at line 236 of file lfVector.h.
References lunchbox::LFVector< T, nSlots >::size().
T& lunchbox::LFVector< T, nSlots >::front | ( | ) | [inline] |
Definition at line 197 of file lfVector.h.
References lunchbox::LFVector< T, nSlots >::empty().
bool lunchbox::LFVector< T, nSlots >::operator!= | ( | const LFVector< T, nSlots > & | rhs | ) | const [inline] |
Definition at line 166 of file lfVector.h.
LFVector& lunchbox::LFVector< T, nSlots >::operator= | ( | const LFVector< T, nSlots > & | from | ) | [inline] |
Definition at line 112 of file lfVector.h.
bool lunchbox::LFVector< T, nSlots >::operator== | ( | const LFVector< T, nSlots > & | rhs | ) | const [inline] |
Definition at line 146 of file lfVector.h.
References lunchbox::LFVector< T, nSlots >::begin(), lunchbox::LFVector< T, nSlots >::end(), and lunchbox::LFVector< T, nSlots >::size().
T& lunchbox::LFVector< T, nSlots >::operator[] | ( | size_t | i | ) | [inline] |
Definition at line 172 of file lfVector.h.
References lunchbox::getIndexOfLastBit().
const T& lunchbox::LFVector< T, nSlots >::operator[] | ( | size_t | i | ) | const [inline] |
Definition at line 185 of file lfVector.h.
References lunchbox::getIndexOfLastBit().
void lunchbox::LFVector< T, nSlots >::pop_back | ( | ) | [inline] |
Remove the last element (STL version).
A concurrent read on the removed item produces undefined results, in particular end() and back().
Definition at line 268 of file lfVector.h.
bool lunchbox::LFVector< T, nSlots >::pop_back | ( | T & | element | ) | [inline] |
Remove the last element (atomic version).
A concurrent read on the removed item produces undefined results, in particular end() and back(). The last element is assigned to the given output element if the vector is not empty. If the vector is empty, element is not touched and false is returned. The whole operation is atomic with other operations changing the size of the vector.
element | the item receiving the value which was stored at the end. |
Definition at line 291 of file lfVector.h.
References lunchbox::LFVector< T, nSlots >::back().
void lunchbox::LFVector< T, nSlots >::push_back | ( | const T & | item | ) | [inline] |
Add an element to the vector.
Completely thread-save with read operations. Existing end() iterators will keep pointing to the old end of the vector. The size is updated after the element is inserted, so size() followed by a read is thread-safe.
item | the element to insert. |
Definition at line 254 of file lfVector.h.
size_t lunchbox::LFVector< T, nSlots >::size | ( | ) | const [inline] |
Definition at line 169 of file lfVector.h.
Referenced by lunchbox::LFVector< T, nSlots >::expand(), and lunchbox::LFVector< T, nSlots >::operator==().