Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
nix::ChunkedVector< T, ChunkSize, MaxChunks > Class Template Reference

#include <chunked-vector.hh>

Public Member Functions

 ChunkedVector (ChunkedVector &&)=delete
 ChunkedVector (const ChunkedVector &)=delete
ChunkedVector & operator= (ChunkedVector &&)=delete
ChunkedVector & operator= (const ChunkedVector &)=delete
uint32_t size () const noexcept
template<typename... Args>
std::pair< T &, uint32_t > add (Args &&... args)
const T & operator[] (uint32_t idx) const &noexcept
template<typename Fn>
void forEach (Fn fn) const

Detailed Description

template<typename T, size_t ChunkSize, size_t MaxChunks>
class nix::ChunkedVector< T, ChunkSize, MaxChunks >

Provides an indexable container like vector<> with memory overhead guarantees like list<> by allocating storage in chunks of ChunkSize elements instead of using a contiguous memory allocation like vector<> does. Not using a single vector that is resized reduces memory overhead on large data sets by on average (growth factor)/2, mostly eliminates copies within the vector during resizing, and provides stable references to its elements.

Thread-safe to append and read concurrently. Caps the maximum number of chunks to MaxChunks for ease of implementation.

Member Function Documentation

◆ forEach()

template<typename T, size_t ChunkSize, size_t MaxChunks>
template<typename Fn>
void nix::ChunkedVector< T, ChunkSize, MaxChunks >::forEach ( Fn fn) const
inline

Iterate over all elements. Do not use when there might be concurrent writers.

◆ operator[]()

template<typename T, size_t ChunkSize, size_t MaxChunks>
const T & nix::ChunkedVector< T, ChunkSize, MaxChunks >::operator[] ( uint32_t idx) const &
inlinenoexcept

Unchecked subscript operator.

Precondition
add must have been called at least idx + 1 times.
Exceptions
nothing

◆ size()

template<typename T, size_t ChunkSize, size_t MaxChunks>
uint32_t nix::ChunkedVector< T, ChunkSize, MaxChunks >::size ( ) const
inlinenoexcept

Get the current size.


The documentation for this class was generated from the following file: