containers.vector
Dynamic array struct.
- struct Vector(T,Allocator = DirectAllocator) if (Allocator.canAllocate!(T));
Simple dynamic array with manually managed memory, with interface similar to D array.
Vector reallocates its storage as new elements are added, moving its contents in memory. It is therefore unsafe to keep pointers to its contents. If you need such functionality, use SegmentedVector instead.
Only bare requirements are implemented. Can be improved if needed.- T[] data_;
Manually allocated data storage. More storage than used can be allocated.
- size_t used_;
Used storage (number of items in the vector).
- void destroy();
Destroy the vector, resetting it back to default-initialized state.
- const @trusted hash_t toHash();
Compute a hash.
- int opApply(int delegate(ref T) dg);
Foreach over values.
Foreach will iterate over all elements of the vector in linear order from start to end.
- int opApply(int delegate(size_t, ref T) dg);
Foreach over indices and values.
Foreach will iterate over all elements of the vector in linear order from start to end.
- void opCatAssign(U : T)(U element);
Append an element to the vector. (operator ~=)
- void opCatAssign(A)(ref A array);
Append contents of a vector or an array to the vector.
- void opAssign(ref Vector v);
Assign another vector to the vector. This will destroy any data owned by this vector and copy data to this vector.
Parameters:Vector v Vector to assign. - void opAssign(T[] array);
Assign an array to the vector. This will destroy any data owned by this vector and copy data to this vector.
Parameters:T[] array Array to assign. - inout pure nothrow inout(T) opIndex(const size_t index);
Get element at the specified index.
Parameters:Returns:size_t index Index of the element to get. Must be within bounds. Element at the specified index.- void opIndexAssign(T value, const size_t index);
Set element at the specified index.
Parameters:size_t index Index of the element to set. Must be within bounds. - void opSliceAssign(T[] array, const size_t start, const size_t end);
Copy an array to specified slice of the vector.
Array and slice length must match.
Parameters:T[] array Array to copy. size_t start Start of the slice. size_t end End of the slice. - nothrow void opSliceAssign(T value);
Set all elements in the vector to specified value.
- inout pure nothrow inout(T[]) opSlice(const size_t start, const size_t end);
Get a slice of the vector as a D array.
Parameters:size_t start Start of the slice. size_t end End of the slice. - inout pure nothrow inout(T[]) opSlice();
Get a slice of the whole vector as a D array.
- inout pure nothrow inout(T) front();
Access the first element of the vector.
- inout pure nothrow inout(T) back();
Access the last element of the vector.
- void popBack();
Remove the last element of the vector.
- const pure nothrow const(T*) ptr();
Access vector contents through a const pointer.
Note that the returned pointer will become invalid once the vector is reallocated.
- pure nothrow T* ptrUnsafe();
Access vector contents through a non-const pointer.
Note that the returned pointer will become invalid once the vector is reallocated.
- const pure nothrow size_t length();
Get number of elements in the vector.
- const pure nothrow bool empty();
- void length(const size_t elements);
-
If the length will be lower than current length, trailing elements will be erased. If higher, the vector will be expanded. Values of the extra elements after expansion are NOT defined.
Parameters: - void reserve(const size_t elements);
Reserve space for at least specified number of elements.
- const pure nothrow size_t allocated();
- void unittestVector();
Unittest for Vector.