gtopt/stable_vector.hpp file

Append-only random-access container with stable references.

StableVector<T> stores its elements in geometrically growing chunks (64, 128, 256, … elements) that are never moved: emplace_back never invalidates a reference, pointer or index to an existing element. Random access is O(1) (a bit-width and two subtractions), and growth never copies or moves the stored elements, so the peak memory of a build does not double at a reallocation either.

LinearProblem keeps its rows and columns here. Element builders take auto& row = lp.row_at(i) and keep stamping through it while other code adds rows; with a std::vector the first reallocation left those references dangling and silently dropped coefficients, so the LP (and the solver result) depended on the memory layout. The stable storage makes that pattern correct by construction.

Namespaces

namespace gtopt

Classes

template<bool Const>
class gtopt::StableVector::Iterator
template<typename T>
class gtopt::StableVector