|
Stratax 0.3.1
|
Version: v0.2.0
Status: Complete
Header: include/stratax/containers/Vector.hpp
stratax::container::Vector<T> is a one-dimensional owning array for types that satisfy the Numeric concept. It derives from core::ArrayBase<T> and uses the base class's contiguous Buffer and Shape metadata. Strides are stored as a second Shape containing canonical row-major stride values.
A normally constructed vector always has rank one. This includes an empty vector, whose shape is {0} and whose size is zero.
Vector<T> is responsible for:
ArrayBase<T>swapThe inherited ArrayBase<T> interface provides:
at(index)operator[]front(), back(), data(), and fill()Vector<T> does not provide multidimensional indexing, broadcasting, or rank-changing operations directly. Those operations belong to other containers or algorithms.
For every normally constructed vector:
rank() == 1shape() == Shape{size()}strides() == Shape{1}size() == shape().elements()As with other movable containers, a moved-from vector remains destructible and assignable, but its previous contents and layout must not be relied upon.
Vector<T> republishes the complete container alias set from core::ArrayBase<T>:
These aliases allow generic contiguous-container code to use Vector<T> without depending directly on Buffer<T>.
Constructs an empty rank-one vector with shape {0} and strides {1}.
Complexity: O(1).
Constructs a rank-one vector with size value-initialized elements. For arithmetic types, value initialization produces zero.
Complexity: O(size).
May throw std::bad_alloc or an exception from value_type construction.
Constructs a value-initialized vector from shape. The shape must have exactly one dimension; both Shape{0} and nonzero rank-one shapes are valid.
Complexity: O(shape.elements()).
Throws:
Exceptions::ShapeError when shape.rank() != 1std::bad_alloc when allocation failsvalue_type constructionConstructs a rank-one vector containing size copies of value.
Complexity: O(size).
May throw std::bad_alloc or an exception from the value_type copy constructor.
Copies the list elements into contiguous storage in their original order. An empty list produces a rank-one vector with shape {0}.
Complexity: O(list.size()).
May throw std::bad_alloc or an exception from the value_type copy constructor.
The compiler-generated special members use ArrayBase<T> semantics:
Copying duplicates the element storage and metadata. Moving transfers their ownership. Copy operations are O(n), while moves are O(1), apart from destroying any state replaced by move assignment.
All metadata queries are O(1).
operator[] is unchecked and requires index < size(). at() checks its argument and accepts indices in [-size(), size()); negative values count from the end. It throws Exceptions::IndexError when the index is invalid.
front() and back() also throw Exceptions::IndexError for an empty vector. All element-access operations are O(1).
Vector does not define operator(). Use operator[] for unchecked access or at() for checked access.
Each iterator lookup is O(1). Traversing the complete vector is O(size()).
Assigns value to every element in O(size()).
Both overloads exchange the buffer, shape, and strides in O(1). The non-member overload supports argument-dependent lookup:
| Operation | Complexity |
|---|---|
| Default construction | O(1) |
| Size, fill, or list construction | O(n) |
| Shape construction | O(shape.elements()) |
| Copy construction or assignment | O(n) |
| Move construction | O(1) |
| Metadata query | O(1) |
| Element access | O(1) |
| Iterator acquisition | O(1) |
| Complete traversal | O(n) |
fill() | O(n) |
swap() | O(1) |
Keeping storage and layout behavior in ArrayBase<T> gives Vector, Matrix, and Tensor consistent ownership, access, and iterator semantics. Vector<T> adds only the construction rules needed to preserve its rank-one abstraction.