|
Click
|
#include <vector.hh>
Public Types | |
| enum | { RESERVE_GROW = (size_type) -1 } |
| Constant passed to reserve() to grow the Vector. More... | |
| typedef T | value_type |
| Value type. | |
| typedef T & | reference |
| Reference to value type. | |
| typedef const T & | const_reference |
| Const reference to value type. | |
| typedef T * | pointer |
| Pointer to value type. | |
| typedef const T * | const_pointer |
| Pointer to const value type. | |
| typedef fast_argument< T >::type | value_argument_type |
| Type used for value arguments (either T or const T &). | |
| typedef const T & | const_access_type |
| typedef int | size_type |
| Type of sizes (size()). | |
| typedef T * | iterator |
| Iterator type. | |
| typedef const T * | const_iterator |
| Const iterator type. | |
Public Member Functions | |
| Vector () | |
| Construct an empty vector. | |
| Vector (size_type n, value_argument_type v) | |
| Construct a vector containing n copies of v. | |
| Vector (const Vector< T, ALIGNMENT > &x) | |
| Construct a vector as a copy of x. | |
| Vector< T, ALIGNMENT > & | operator= (const Vector< T, ALIGNMENT > &x) |
| Replace this vector's contents with a copy of x. | |
| Vector< T, ALIGNMENT > & | assign (size_type n, value_argument_type v=T()) |
| Replace this vector's contents with n copies of v. | |
| iterator | begin () |
| Return an iterator for the first element in the vector. | |
| iterator | end () |
| Return an iterator for the end of the vector. | |
| const_iterator | begin () const |
| const_iterator | end () const |
| const_iterator | cbegin () const |
| Return a const_iterator for the beginning of the vector. | |
| const_iterator | cend () const |
| Return a const_iterator for the end of the vector. | |
| size_type | size () const |
| Return the number of elements. | |
| size_type | capacity () const |
| Return the vector's capacity. | |
| bool | empty () const |
| Test if the vector is empty (size() == 0). | |
| void | resize (size_type n, value_argument_type v=T()) |
| Resize the vector to contain n elements. | |
| bool | reserve (size_type n) |
| Reserve space for at least n more elements. | |
| T & | operator[] (size_type i) |
| Return a reference to the ith element. | |
| const T & | operator[] (size_type i) const |
| T & | at (size_type i) |
| Return a reference to the ith element. | |
| const T & | at (size_type i) const |
| T & | front () |
| Return a reference to the first element. | |
| const T & | front () const |
| T & | back () |
| Return a reference to the last element (number size()-1). | |
| const T & | back () const |
| T & | unchecked_at (size_type i) |
| Return a reference to the ith element. | |
| const T & | unchecked_at (size_type i) const |
| T & | at_u (size_type i) |
| const T & | at_u (size_type i) const |
| T * | data () |
| Return a pointer to the vector's data. | |
| const T * | data () const |
| void | push_back (value_argument_type v) |
| Append element v. | |
| void | pop_back () |
| Remove the last element. | |
| void | push_front (value_argument_type v) |
| Prepend element v. | |
| void | pop_front () |
| Remove the first element. | |
| iterator | insert (iterator it, value_argument_type v) |
| Insert v before position it. | |
| iterator | erase (iterator it) |
| Remove the element at position it. | |
| iterator | erase (iterator a, iterator b) |
| Remove the elements in [a, b). | |
| void | fill (T value) |
| void | clear () |
| Remove all elements. | |
| Vector< T, ALIGNMENT > | sub (size_type begin, size_type sz) |
| Swap the contents of this vector and x. | |
| void | swap (Vector< T, ALIGNMENT > &x) |
| Swap the contents of this vector and x. | |
| void | shuffle (int n) |
Vector template.
never
Vector implements a vector, or growable array, suitable for use in the kernel or at user level. Its interface should be compatible with C++'s std::vector, although that type has more methods. Vector elements are accessed with operator[] like arrays, and can be resized and expanded through append operations (see push_back() and resize()). A common (and efficient) usage pattern grows a Vector through repeated push_back() calls.
Vector iterators are pointers into the underlying array. This can simplify interactions between Vector and code that expects conventional C arrays.
Vector's push_front() and pop_front() operations are quite expensive (O(size()) complexity). For fast push_front() and pop_front() operations, use Deque.
Example code:
| typedef T Vector< T, ALIGNMENT >::value_type |
Value type.
| typedef T& Vector< T, ALIGNMENT >::reference |
Reference to value type.
| typedef const T& Vector< T, ALIGNMENT >::const_reference |
Const reference to value type.
| typedef T* Vector< T, ALIGNMENT >::pointer |
Pointer to value type.
| typedef const T* Vector< T, ALIGNMENT >::const_pointer |
Pointer to const value type.
| typedef fast_argument<T>::type Vector< T, ALIGNMENT >::value_argument_type |
Type used for value arguments (either T or const T &).
| typedef int Vector< T, ALIGNMENT >::size_type |
Type of sizes (size()).
| typedef T* Vector< T, ALIGNMENT >::iterator |
Iterator type.
| typedef const T* Vector< T, ALIGNMENT >::const_iterator |
Const iterator type.
| anonymous enum |
Construct an empty vector.
|
inlineexplicit |
Construct a vector containing n copies of v.
|
inline |
Construct a vector as a copy of x.
|
inline |
Replace this vector's contents with a copy of x.
|
inline |
Replace this vector's contents with n copies of v.
|
inline |
Return an iterator for the first element in the vector.
|
inline |
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
Return a const_iterator for the beginning of the vector.
|
inline |
|
inline |
Return the number of elements.
|
inline |
Return the vector's capacity.
The capacity is greater than or equal to the size(). Functions such as resize(n) will not allocate new memory for the vector if n <= capacity().
|
inline |
Test if the vector is empty (size() == 0).
|
inline |
Resize the vector to contain n elements.
| n | new size |
| v | value used to fill new elements |
Reserve space for at least n more elements.
This function changes the vector's capacity(), not its size(). If reserve(n) succeeds, then any succeeding call to resize(m) with m < n will succeed without allocating vector memory.
|
inline |
Return a reference to the ith element.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
Return a reference to the first element.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
Return a reference to the last element (number size()-1).
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
Return a reference to the ith element.
Unlike operator[]() and at(), this function does not check bounds, even if assertions are enabled. Use with caution.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
Append element v.
A copy of v is inserted at position size(). Takes amortized O(1) time.
|
inline |
Remove the last element.
Takes O(1) time.
|
inline |
Prepend element v.
A copy of v is added to position 0. Other elements are shifted one position forward. Takes O(size()) time.
|
inline |
Remove the first element.
Other elements are shifted one position backward. Takes O(size()) time.
|
inline |
Insert v before position it.
|
inline |
Remove the element at position it.
|
inline |
Remove the elements in [a, b).
|
inline |
Remove all elements.
|
inline |
Swap the contents of this vector and x.
|
inline |
Swap the contents of this vector and x.