Template Class Vector¶
- Defined in File vector.h
Inheritance Relationships¶
Base Type¶
public shad::AbstractDataStructure< Vector< T, Allocator > >
(Template Class AbstractDataStructure)
Class Documentation¶
-
template <typename T, typename Allocator = std::allocator<T>>
classVector
: public shad::AbstractDataStructure<Vector<T, Allocator>>¶ The Vector data Structure.
shad::Vector is a distributed container that can grow dynamically.
- Warning
- The contained type must be trivially copiable.
- Template Parameters
T
: The type of the entries stored in a shad::Vector.Allocator
: The allocator to be used.
Capacity
-
Vector<T, Allocator>::size_type
Size
() const¶ Returns the number of element stored in the shad::Vector.
- Return
- the number of element in the container.
-
Vector<T, Allocator>::size_type
MaxSize
() const¶ Returns the maximum number of elements that shad::Vector can hold.
This methods returns the maximum potential size of the container. However, there is no guarantee that a shad::Vector will be able to reach that size (i.e., the system might fail to allocate memory before that size is reached).
-
Vector<T, Allocator>::size_type
Capacity
() const¶ Return the size of the allocated storage capacity.
The capacity of a shad::Vector represent the maximum number of element that the currently allocated storage can hold without the need to expand. Notice that this does not imply a limit on the Vector size. In fact, when the current capacity is exhausted and more is needed, the container will expand its capacity allocating more memory.
- Return
- The size of the currently allocated storage capacity.
-
bool
Empty
() const¶ Returns whether the shad::Vector is empty.
- Return
- true if the container Size is 0, false otherwise.
-
void
Reserve
(size_type n)¶ Request that the Capacity is at least n.
Request that the Capacity is enough to store n elements. If n is greater than the current Capacity, the function will cause the container to expand increasing its Capacity to n. In all the other cases, the function does not affect the Capacity of the shad::Vector.
- Warning
- Reserve is not thread safe, so don’t try to reserve from multiple concurrent tasks.
- Parameters
n
: The requested minimum Capacity for the shad::Vector.
-
void
Resize
(size_type n)¶ Resize the container so that it contains n elements.
Resize the container so that it contains n elements. If n is smaller than the container Size, the content is reduced to the first n elements. If n is greater than the current Size, the container is expanded by inserting at the end as many elements as needed to reach a size of n.
If n is greater than the current capacity, more data blocks will be allocated to extend the capacity to at least n elements.
- Parameters
n
: The new container size, expressend in number of elements.
Element Access
-
Vector<T, Allocator>::value_type
At
(size_type n) const¶ Return the element in position n in the shad::Vector.
This methods check whether the requested position is within the bounds of the vector. If the position is out of bounds, the method will throw an std::out_of_range exception.
- Return
- the element in position n.
- Parameters
n
: The position of an element in the container.
-
Vector<T, Allocator>::value_type
operator[]
(size_type n) const¶ Return the element in position n in the shad::Vector.
This methods is similar to At but it is not bound checked.
- Return
- the element in position n.
- Parameters
n
: The position of an element in the container.
-
Vector<T, Allocator>::value_type
Front
() const¶ Return the first element in the shad::Vector.
- Warning
- Calling this method on an empty container causes undefined behavior.
- Return
- The first element in the shad::Vector.
-
Vector<T, Allocator>::value_type
Back
() const¶ Return the last element in the shad::Vector.
- Warning
- Calling this method on an empty container causes undefined behavior.
- Return
- The last element in the shad::Vector.
-
void
AsyncAt
(rt::Handle &handle, size_type n, T *result) const¶ Return the element in position n in the shad::Vector.
This methods check whether the requested position is within the bounds of the vector. If the position is out of bounds, the method will throw an std::out_of_range exception.
- Parameters
handle
: The handle that will be used for the spawned tasks.n
: The position of an element in the container.result
: The address where to store the result.
Modifiers
-
void
Clear
()¶ Removes all the elements from the shad::Vector.
Removes all the elements from the container (destroying them). It leaves the container with a size and a capacity of 0.
-
void
PushBack
(const T &value)¶ Adds an element at the end of the shad::Vector.
-
Vector<T, Allocator>::iterator
InsertAt
(shad::Vector<T, Allocator>::size_type position, const shad::Vector<T, Allocator>::value_type &value)¶ Write a value at the specified position.
This method overwrite the element at the specified position.
Typical usage:
auto vectorPtr = shad::Vector<size_t>::Create(kVectorSize); for (size_t i = 0; i < kVectorSize; i++) { vectorPtr->InsertAt(i, i+1); }
- Warning
- The semantic of this method is different from the insert method of the std::vector. The shad::Vector will overwrite the element at poisition.
- Return
- An iterator that points to the inserted value.
- Parameters
position
: Position where to write the given value.value
: Value to be written at the specified position.
-
template <typename InputIterator>
iteratorInsertAt
(size_type position, InputIterator begin, InputIterator end)¶ Write a sequence of elements starting at the specified position.
Typical usage:
auto vectorPtr = shad::Vector<size_t>::Create(kVectorSize); vectorPtr->InsertAt( aPosition, std::begin(someSequence), std::end(someSequence));
- Warning
- The semantic of this method is different from the insert method of the std::vector. The shad::Vector will not make room for the newly inserted elements shifting all the element from position to the end for performance reasons.
- Return
- An iterator that points to the first inserted value.
- Parameters
position
: Position where to write the given value.position
: Position where to write the given value.begin
: An input iterator to the start of the sequence to insert.end
: An input iterator to the end of the sequence to insert.
-
void
AsyncInsertAt
(rt::Handle &handle, shad::Vector<T, Allocator>::size_type position, const shad::Vector<T, Allocator>::value_type &value)¶ Write a value at the specified position asynchronously.
This method overwrite the element at the specified position. When writing one past the last element, the method will grow the container size by one inserting the value at the end.
Typical usage:
shad::rt::Handle handle; auto vectorPtr = shad::Vector<size_t>::Create(kVectorSize); for (size_t i = 0; i < kVectorSize; i++) { vectorPtr->AsyncInsertAt(handle, i, i+1); } // ... do other work ... shad::rt::waitForCompletion(handle);
- Warning
- The semantic of this method is different from the insert method of the std::vector. The shad::Vector will NOT make room for the newly inserted element and shift all the element by 1 from position to the end for performance reasons.
- Parameters
handle
: The handle that will be used for the spawned tasks.position
: Position where to write the given value.value
: Value to be written at the specified position.
-
template <typename InputIterator>
voidAsyncInsertAt
(rt::Handle &handle, size_type position, InputIterator begin, InputIterator end)¶ Write a sequence of elements starting at the specified position asynchronously.
Typical usage:
shad::rt::Handle handle; auto vectorPtr = shad::Vector<size_t>::Create(kVectorSize); vectorPtr->AsyncInsertAt( handle, aPosition, std::begin(someSequence), std::end(someSequence)); // ... do other work ... shad::rt::waitForCompletion(handle);
- Warning
- The semantic of this method is different from the insert method of the std::vector. The shad::Vector will not make room for the newly inserted elements shifting all the element from position to the end for performance reasons.
- Parameters
handle
: The handle that will be used for the spawned tasks.position
: Position where to write the given value.begin
: An input iterator to the start of the sequence to insert.end
: An input iterator to the end of the sequence to insert.
-
void
BufferedInsertAt
(const size_type pos, const value_type &value)¶ Buffered Insert method.
Inserts an element at the specified position, using aggregation buffers.
Typical usage:
auto vectorPtr = shad::Vector<size_t>::Create(kVectorSize); for (size_t i = 0; i < kVectorSize; i++) { vectorPtr->BufferedInsertAt(handle, i, i+1); } vectorPtr->WaitForBufferedInsert();
- Warning
- Insertions are finalized only after calling the WaitForBufferedInsert() method.
- Parameters
pos
: The target position.value
: The value of the element to be inserted.
-
void
BufferedAsyncInsertAt
(rt::Handle &handle, const size_type pos, const value_type &value)¶ Asynchronous Buffered Insert method.
Asynchronously inserts an element at the specified position, using aggregation buffers.
Typical usage:
shad::rt::Handle handle; auto vectorPtr = shad::Vector<size_t>::Create(kVectorSize); for (size_t i = 0; i < kVectorSize; i++) { vectorPtr->BufferedAsyncInsertAt(handle, i, i+1); } // ... do other work ... shad::rt::waitForCompletion(handle); vectorPtr->WaitForBufferedInsert();
- Warning
- asynchronous buffered insertions are finalized only after calling the shad::rt::waitForCompletion(rt::Handle &handle) method and the WaitForBufferedInsert() method, in this order.
- Parameters
handle
: Reference to the handle to be used to wait for completion.pos
: The target position.value
: The value to be inserted.
-
void
WaitForBufferedInsert
()¶ Finalize method for buffered insertions.
Algorithms
-
template <typename ApplyFunT, typename... Args>
voidApply
(const size_type position, ApplyFunT &&function, Args&... args)¶ Applies a user-defined function to an element.
Applies a user-defined function to the element at the specified position. Typical usage:
void fn(size_t, size_t& elem, size_t& aValue) { // ... do something ... } // ... auto vectorPtr = shad::Vector<size_t>::Create(kVectorSize); for (size_t i = 0; i < kVectorSize; i++) { vectorPtr->Apply(i, fn, aValue); }
- Template Parameters
ApplyFunT
: User-defined function type. The function prototype should be:void(size_t, T&, Args& args);
...Args
: Types of the function arguments.
- Parameters
position
: The target position.function
: The function to apply.args
: The function arguments.
-
template <typename ApplyFunT, typename... Args>
voidAsyncApply
(rt::Handle &handle, const size_type position, ApplyFunT &&function, Args&... args)¶ Asynchronously applies a user-defined function to an element.
Asynchronously applies a user-defined function to the element at the specified position.
Typical usage:
void fn(shad::rt::Handle&, size_t i, size_t& elem, size_t& aValue) { // ... do something ... } // ... auto vectorPtr = shad::Vector<size_t>::Create(kVectorSize); shad::rt::Handle handle; for (size_t i = 0; i < kVectorSize; i++) { vectorPtr->AsyncApply(handle, i, fn, aValue); } shad::rt::waitForCompletion(handle);
- Warning
- Asynchronous operations are guaranteed to have completed only after calling the shad::rt::waitForCompletion(rt::Handle &handle) method.
- Template Parameters
ApplyFunT
: User-defined function type. The function prototype should be:void(shad::rt::Handle&, size_t, T&, Args& args);
...Args
: Types of the function arguments.
- Parameters
handle
: Reference to the handle to be used to wait for completion.position
: The target position.function
: The function to apply.args
: The function arguments.
-
template <typename ApplyFunT, typename... Args>
voidForEachInRange
(const size_type first, const size_type last, ApplyFunT &&function, Args&... args)¶ Applies a user-defined function to every element in the specified range.
Applies a user-defined function to all the elements in the specified range of positions.
Typical usage:
void fn(size_t& elem, size_t& aValue) { // ... do something ... } // ... auto vectorPtr = shad::Vector<size_t>::Create(kVectorSize); edsPtr->ForEachInRange(0, kVectorSize, fn, aValue);
- Template Parameters
ApplyFunT
: User-defined function type. The function prototype should be:void(T&, Args& args);
...Args
: Types of the function arguments.
- Parameters
first
: The first position of the range.last
: The last position of the range.function
: The function to apply.args
: The function arguments.
-
template <typename ApplyFunT, typename... Args>
voidAsyncForEachInRange
(rt::Handle &handle, const size_type first, const size_type last, ApplyFunT &&function, Args&... args)¶ Asynchronously applies a user-defined function to every element in the specified range.
Asynchronously applies a user-defined function to all the elements in the specified range of positions.
Typical usage:
void asyncApplyFun(rt::Handle&, size_t& elem, size_t& aValue) { // ... do something ... } // ... auto vectorPtr = shad::Vector<size_t>::Create(kVectorSize); rt::Handle handle; vectorPtr->AsyncForEachInRange(0, kVectorSize, kVectorSize, aValue); // ... do other work ... shad::rt::waitForCompletion(handle);
- Warning
- Asynchronous operations are guaranteed to have completed only after calling the shad::rt::waitForCompletion(rt::Handle &handle) method.
- Template Parameters
ApplyFunT
: User-defined function type. The function prototype should be:void(shad::rt::Handle&, T&, Args& args);
...Args
: Types of the function arguments.
- Parameters
handle
: Reference to the handle to be used to wait for completion.first
: The first position of the range.last
: The last position of the range.function
: The function to apply.args
: The function arguments.
Public Types
-
template<>
usingallocator_type
= Allocator¶ The type of the allocator.
-
template<>
usingvalue_type
= T¶ The type of the elements stored in the shad::Vector.
-
template<>
usingdifference_type
= typename allocator_type::difference_type¶ A signed integral type used the difference between iterators.
-
template<>
usingsize_type
= typename allocator_type::size_type¶ An unsigned integral type that can represent any non-negative value of difference_type.
-
template<>
usingiterator
= Iterator<T>¶ A random access iterator to shad::Vector::value_type.
-
template<>
usingconst_iterator
= Iterator<const T>¶ A random access iterator to const shad::Vector::value_type.
-
template<>
usingObjectID
= typename AbstractDataStructure::ObjectID¶ The type of the unique identifier for the Vector.
Public Functions
-
ObjectID
GetGlobalID
() const¶ DataStructure identifier getter.
Returns the global object identifier associated to a DataStructure instance.
- Warning
- It must be implemented in the inheriting DataStructure.
-
~Vector
()¶ Destructor.
-
void
BufferEntryInsert
(const std::tuple<size_type, value_type> entry)¶
-
template <typename IteratorType>
Vector<T, Allocator>::iteratorInsertAt
(Vector<T, Allocator>::size_type position, IteratorType begin, IteratorType end)¶
-
template <typename IteratorType>
voidAsyncInsertAt
(rt::Handle &handle, Vector<T, Allocator>::size_type position, IteratorType begin, IteratorType end)¶
Protected Functions
-
Vector
(ObjectID oid, size_type n)¶
Friends
-
friend
shad::Vector::impl::BuffersVector< std::tuple< size_t, T >, Vector< T, Allocator > >