gtopt/lp_snapshot_holder.hpp file

LpSnapshotHolder — snapshot + codec + compression facade.

Phase 2b of the LinearInterface split.

LpSnapshotHolder owns the 2 fields that previously lived directly on LinearInterface:

  • m_snapshot_ — LowMemorySnapshot carrying the flat LP (uncompressed or compressed buffer) used by the compress/snapshot reconstruct path.
  • m_memory_codec_ — CompressionCodec selected at set_low_memory() time (default zstd).

Plus the two compression helpers that gate purely on the snapshot's own state (without consulting m_low_memory_mode_):

  • compress_if_uncompressed() — first-time compress + log via a caller-supplied logger.
  • decompress_if_compressed() — re-hydrate the flat LP buffer.

LinearInterface::enable_compression / LinearInterface::disable_compression retain their public surface but become thin facades that gate on m_low_memory_mode_ then call into this holder.

Invariants (asserted in debug, see validate_consistency()):

  • S1. Default-constructed LpSnapshotHolder{} reports has_data() == false, is_compressed() == false, codec() == CompressionCodec::zstd.
  • S2. clear() resets the snapshot to an empty LowMemorySnapshot and leaves the codec untouched.
  • S3. decompress_if_compressed() is idempotent — calling it on a non-compressed snapshot is a no-op.
  • S4. compress_if_uncompressed() returns true iff this call performed the first compression (i.e. the snapshot transitioned from uncompressed to compressed); subsequent calls return false.
  • S5. set_codec(c) only changes the codec used by future compress_if_uncompressed() calls. An already- compressed snapshot keeps its original codec.

Namespaces

namespace gtopt

Classes

class gtopt::LpSnapshotHolder
Snapshot + codec holder for LinearInterface low-memory paths.