4#ifndef CBM_ALGO_BASE_PARTITIONED_VECTOR_H
5#define CBM_ALGO_BASE_PARTITIONED_VECTOR_H
10#include <boost/serialization/access.hpp>
11#include <boost/serialization/vector.hpp>
29 template<
typename T,
class Allocator = std::allocator<T>>
52 ,
fAdresses(addresses.begin(), addresses.end())
61 template<
typename OtherAllocator>
178 throw std::runtime_error(
"PartitionedVector: fOffsets.size() != fAdresses.size()");
181 throw std::runtime_error(
"PartitionedVector: fOffsets.front() != 0");
184 throw std::runtime_error(
"PartitionedVector: fOffsets.back() != fData.size()");
190 if (i >=
fAdresses.size())
throw std::out_of_range(
"PartitionedVector: index out of bounds");
197 for (
auto n : sizes) {
214 template<
class Archive>
A vector that is partitioned into multiple subvectors.
void ComputeOffsets(gsl::span< const size_t > sizes)
size_t SizeBytes() const
Return total size in bytes of the underlying data.
const std::vector< u32 > & Addresses() const
Get the addresses.
void serialize(Archive &ar, unsigned int)
std::pair< gsl::span< const T >, u32 > Partition(size_t i) const
Get a pair of the data and the hardware address of partition i.
std::vector< size_t > fOffsets
PartitionedVector(PartitionedSpan< U > other)
gsl::span< const T > Data() const
Get the underlying data.
gsl::span< T > UnsafePartitionSpan(size_t i)
std::pair< gsl::span< T >, u32 > Partition(size_t i)
Get a pair of the data and the hardware address of partition i.
size_t Size(size_t i) const
Get the size of partition i.
gsl::span< T > operator[](size_t i)
Access data at partition i.
size_t UnsafeSize(size_t i) const
std::vector< T, Allocator > Container_t
void EnsureDimensions() const
PartitionedVector(Container_t &&data, gsl::span< const size_t > sizes, gsl::span< const u32 > addresses)
Constructor. Creates a vector with n partitions.
PartitionedVector()
Default constructor. Creates an empty vector.
gsl::span< T > Data()
Get the underlying data.
const std::vector< size_t > & Offsets() const
Get the underlying offsets.
size_t NElements() const
Get the total number of elements in the container across all partitions.
friend class boost::serialization::access
std::vector< u32 > fAdresses
size_t NPartitions() const
Get the number of partitions.
gsl::span< const T > UnsafePartitionSpan(size_t i) const
u32 Address(size_t i) const
Get the hardware address of partition i.
gsl::span< const T > operator[](size_t i) const
Access data at partition i.
void EnsureBounds(size_t i) const
PartitionedVector(const PartitionedVector< T, OtherAllocator > &other)
Copy constructor. Copy the data from other vector.