4#ifndef CBM_ALGO_BASE_PARTITIONED_VECTOR_H
5#define CBM_ALGO_BASE_PARTITIONED_VECTOR_H
9#include <boost/serialization/access.hpp>
10#include <boost/serialization/vector.hpp>
28 template<
typename T,
class Allocator = std::allocator<T>>
51 ,
fAddresses(addresses.begin(), addresses.end())
60 template<
typename OtherAllocator>
108 if (
this != &other) {
121 if (
this != &other) {
122 fData = std::move(other.fData);
123 fOffsets = std::move(other.fOffsets);
125 other.fOffsets = {0};
180 std::pair<gsl::span<const T>, uint32_t>
Partition(
size_t i)
const
239 throw std::runtime_error(
"PartitionedVector: fOffsets.size() - 1 != fAddresses.size()");
242 throw std::runtime_error(
"PartitionedVector: fOffsets.front() != 0");
245 throw std::runtime_error(
"PartitionedVector: fOffsets.back() != fData.size()");
251 if (i >=
fAddresses.size())
throw std::out_of_range(
"PartitionedVector: index out of bounds");
258 for (
auto n : sizes) {
273 friend class boost::serialization::access;
275 template<
class Archive>
std::vector< T, PODAllocator< T > > Container_t
A vector that is partitioned into multiple subvectors.
std::pair< gsl::span< const T >, uint32_t > Partition(size_t i) const
Get a pair of the data and the hardware address of partition i.
std::vector< T, Allocator > Container_t
void EnsureDimensions() const
PartitionedVector(Container_t &&data, gsl::span< const size_t > sizes, gsl::span< const uint32_t > addresses)
Constructor. Creates a vector with n partitions.
std::vector< uint32_t > fAddresses
Addresses of the partitions.
gsl::span< const T > Data() const
Get the underlying data.
void ComputeOffsets(gsl::span< const size_t > sizes)
void serialize(Archive &ar, unsigned int)
PartitionedVector(const PartitionedVector< T, OtherAllocator > &other)
Copy constructor. Copy the data from other vector.
const std::vector< uint32_t > & Addresses() const
size_t UnsafeSize(size_t i) const
uint32_t Address(size_t i) const
Get the hardware address of partition i.
PartitionedVector(PartitionedVector< T, Allocator > &&other)
Move constructor.
gsl::span< T > operator[](size_t i)
Access data at partition i.
std::vector< size_t > fOffsets
void Clear()
Clears the vector.
PartitionedVector(PartitionedSpan< U > other)
gsl::span< T > UnsafePartitionSpan(size_t i)
size_t Size(size_t i) const
Get the size of partition i.
const std::vector< size_t > & Offsets() const
PartitionedVector(const PartitionedVector< T, Allocator > &other)
Copy constructor for a given type (to satisfy the rule of five)
PartitionedVector()
Default constructor. Creates an empty vector.
PartitionedVector & operator=(const PartitionedVector< T, Allocator > &other)
Copy assignment operator.
gsl::span< const T > operator[](size_t i) const
Access data at partition i.
PartitionedVector & operator=(PartitionedVector< T, Allocator > &&other)
Move assignment operator.
size_t NPartitions() const
Get the number of partitions.
size_t NElements() const
Get the total number of elements in the container across all partitions.
gsl::span< const T > UnsafePartitionSpan(size_t i) const
size_t SizeBytes() const
Return total size in bytes of the underlying data.
std::pair< gsl::span< T >, uint32_t > Partition(size_t i)
Get a pair of the data and the hardware address of partition i.
void EnsureBounds(size_t i) const
PartitionedVector< T, PODAllocator< T > > PartitionedPODVector