morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
morph::table::TableSnapshot Class Referencefinal

A RowSnapshot that stores rows in shared, immutable chunks. More...

#include <data_source.hpp>

Inheritance diagram for morph::table::TableSnapshot:
morph::table::RowSnapshot

Public Member Functions

 TableSnapshot (std::size_t columnCount)
 Constructs an empty snapshot.
std::size_t rowCount () const override
 The number of rows.
std::size_t columnCount () const noexcept
 The number of columns.
RowId rowId (std::size_t row) const override
 A row's key.
Cell cell (std::size_t row, std::size_t column) const override
 One cell.
void readColumn (std::size_t column, ColumnSink &sink, std::size_t first, std::size_t last) const override
 Hands rows [first, last) of column to sink, one run per chunk.
std::shared_ptr< TableSnapshot const > withRow (std::size_t row, std::vector< Cell > cells) const
 A copy of this snapshot with one row's cells replaced. Only that row's chunk is copied.
std::shared_ptr< TableSnapshot const > withInserted (std::size_t row, RowId key, std::vector< Cell > cells) const
 A copy with a row inserted before row. Chunks before it are shared.
std::shared_ptr< TableSnapshot const > withRemoved (std::size_t row) const
 A copy with row row removed. Chunks before it are shared.
bool sharesChunk (TableSnapshot const &other, std::size_t row) const noexcept
 Whether this snapshot and other share the chunk holding row.

Static Public Member Functions

static std::shared_ptr< TableSnapshot const > fromRows (std::size_t columnCount, std::vector< RowId > ids, std::vector< std::vector< Cell > > rows)
 Builds a snapshot from rows.

Static Public Attributes

static constexpr std::size_t kChunkRows = 256
 Rows per chunk: small enough that copying one is cheap, large enough that a column read hands long runs.

Additional Inherited Members

Protected Member Functions inherited from morph::table::RowSnapshot
 RowSnapshot (RowSnapshot const &)=default
 Copies the base of a snapshot: a derived snapshot makes a changed copy of itself this way.
 RowSnapshot (RowSnapshot &&)=default
 Moves the base of a snapshot.
RowSnapshot & operator= (RowSnapshot const &)=default
 Copy-assigns the base of a snapshot.
RowSnapshot & operator= (RowSnapshot &&)=default
 Move-assigns the base of a snapshot.

Detailed Description

A RowSnapshot that stores rows in shared, immutable chunks.

Changing one row produces a new snapshot that shares every chunk but the one holding the row, so a stream of updates against a table a worker is still reading costs one chunk copy per update, not one table copy.

Definition at line 513 of file data_source.hpp.

Constructor & Destructor Documentation

◆ TableSnapshot()

morph::table::TableSnapshot::TableSnapshot ( std::size_t columnCount)
inlineexplicit

Constructs an empty snapshot.

Parameters
columnCountNumber of columns every row has.

Definition at line 521 of file data_source.hpp.

Member Function Documentation

◆ fromRows()

std::shared_ptr< TableSnapshot const > morph::table::TableSnapshot::fromRows ( std::size_t columnCount,
std::vector< RowId > ids,
std::vector< std::vector< Cell > > rows )
inlinestaticnodiscard

Builds a snapshot from rows.

Parameters
columnCountNumber of columns.
idsThe rows' keys.
rowsThe rows' cells; each row has columnCount cells (missing cells are empty, extra cells are dropped).
Returns
The snapshot.

Definition at line 529 of file data_source.hpp.

◆ rowCount()

std::size_t morph::table::TableSnapshot::rowCount ( ) const
inlinenodiscardoverridevirtual

The number of rows.

Returns
Row count.

Implements morph::table::RowSnapshot.

Definition at line 538 of file data_source.hpp.

◆ columnCount()

std::size_t morph::table::TableSnapshot::columnCount ( ) const
inlinenodiscardnoexcept

The number of columns.

Returns
Column count.

Definition at line 542 of file data_source.hpp.

◆ rowId()

RowId morph::table::TableSnapshot::rowId ( std::size_t row) const
inlinenodiscardoverridevirtual

A row's key.

Parameters
rowRow index.
Returns
The key.

Implements morph::table::RowSnapshot.

Definition at line 547 of file data_source.hpp.

◆ cell()

Cell morph::table::TableSnapshot::cell ( std::size_t row,
std::size_t column ) const
inlinenodiscardoverridevirtual

One cell.

Parameters
rowRow index.
columnColumn index.
Returns
The cell.

Implements morph::table::RowSnapshot.

Definition at line 555 of file data_source.hpp.

◆ readColumn()

void morph::table::TableSnapshot::readColumn ( std::size_t column,
ColumnSink & sink,
std::size_t first,
std::size_t last ) const
inlineoverridevirtual

Hands rows [first, last) of column to sink, one run per chunk.

Parameters
columnColumn index.
sinkReceives the cells.
firstFirst row.
lastOne past the last row.

Reimplemented from morph::table::RowSnapshot.

Definition at line 564 of file data_source.hpp.

◆ withRow()

std::shared_ptr< TableSnapshot const > morph::table::TableSnapshot::withRow ( std::size_t row,
std::vector< Cell > cells ) const
inlinenodiscard

A copy of this snapshot with one row's cells replaced. Only that row's chunk is copied.

Parameters
rowRow index.
cellsThe new cells.
Returns
The new snapshot.

Definition at line 579 of file data_source.hpp.

◆ withInserted()

std::shared_ptr< TableSnapshot const > morph::table::TableSnapshot::withInserted ( std::size_t row,
RowId key,
std::vector< Cell > cells ) const
inlinenodiscard

A copy with a row inserted before row. Chunks before it are shared.

Parameters
rowInsert position, at most rowCount().
keyThe new row's key.
cellsThe new row's cells.
Returns
The new snapshot.

Definition at line 595 of file data_source.hpp.

◆ withRemoved()

std::shared_ptr< TableSnapshot const > morph::table::TableSnapshot::withRemoved ( std::size_t row) const
inlinenodiscard

A copy with row row removed. Chunks before it are shared.

Parameters
rowRow index.
Returns
The new snapshot.

Definition at line 608 of file data_source.hpp.

◆ sharesChunk()

bool morph::table::TableSnapshot::sharesChunk ( TableSnapshot const & other,
std::size_t row ) const
inlinenodiscardnoexcept

Whether this snapshot and other share the chunk holding row.

Parameters
otherAnother snapshot.
rowRow index valid in both.
Returns
true when the chunk is the same object.

Definition at line 621 of file data_source.hpp.

Member Data Documentation

◆ kChunkRows

std::size_t morph::table::TableSnapshot::kChunkRows = 256
staticconstexpr

Rows per chunk: small enough that copying one is cheap, large enough that a column read hands long runs.

Definition at line 517 of file data_source.hpp.


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