boostorg / container

STL-like containers from Boost
http://www.boost.org/libs/container/
Boost Software License 1.0
96 stars 116 forks source link

New container: chunked_vector #274

Open HDembinski opened 2 months ago

HDembinski commented 2 months ago

For Boost.Histogram, I need a new type of container. I plan to implement a private version to keep histogram decoupled from Boost.Container, but I wanted to propose this type of container for Boost.Container.

The container should store chunks of homogenous types with fixed length, which is defined at runtime, not compile time.

The container is internally implemented like std::vector, memory is contiguous. The element of the container is not a single value, but a chunk of values with fixed size, which is defined at runtime when the container is created. The value type of the container should be static_vector or small_vector, while its reference types should based on boost::span.

Basically, this is a much more efficient version of std::vector<std::vector<T>> for the case when you know that the inner vector will always have same length, but you don't know this length at compile-time, so you cannot use std::vector<std::array<T, N>>.

I tentatively call this chunked_vector, but I hope you come up with a better name.

igaztanaga commented 1 month ago

This seems like a quite specialized container, I don't feel it's general enough for Boost.Container. One option would be to add the option to dynamically specify the size of the chunk ("block", in boost::container::deque terminology). Currently the block size can be specified at compile-time, but if it could be specified at runtime, then a specialized container like yours would be easy to implement.