Nebula
Loading...
Searching...
No Matches
MemDb::Table Class Reference

#include <table.h>

Classes

class  Partition
 

Public Member Functions

bool HasAttribute (AttributeId attribute) const
 Check if a column exists in the table.
 
AttributeId GetAttributeId (ColumnIndex columnIndex) const
 Returns the attribute located in given column.
 
ColumnIndex GetAttributeIndex (AttributeId attribute) const
 Returns the index of the attribute or invalid if attribute is missing from table.
 
Util::Array< AttributeId > const & GetAttributes () const
 Get the all descriptors for a table.
 
TableSignature const & GetSignature () const
 Get the table signature.
 
ColumnIndex AddAttribute (AttributeId attribute, bool updateSignature=true)
 Add an attribute to the table.
 
RowId AddRow ()
 Add/Get a free row from the table.
 
void RemoveRow (RowId row)
 Deallocate a row from a table. This only frees the row for recycling. See Defragment.
 
SizeT GetNumRows () const
 Get total number of rows in a table.
 
void SetNumRows (SizeT value)
 set total number of rows in a table. This does not allocate any memory or create instaces, thus should pretty much never be used.
 
void SetToDefault (RowId row)
 Set all row values to default.
 
SizeT Defragment (std::function< void(Partition *, RowId, RowId)> const &moveCallback)
 Defragment table.
 
void Clean ()
 Clean table. Does not deallocate anything; just sets the size of the table to zero.
 
void Reset ()
 Reset table. Deallocate all data.
 
PartitionGetFirstActivePartition ()
 Get first active partition with entities.
 
uint16_t GetNumActivePartitions () const
 Get number of partitions that contain entities.
 
uint16_t GetNumPartitions () const
 Get number of partitions in table.
 
PartitionGetCurrentPartition ()
 Get current partition.
 
PartitionGetPartition (uint16_t partitionId)
 
void * GetValuePointer (ColumnIndex cid, RowId row)
 get a buffer. Might be invalidated if rows are allocated or deallocated
 
void * GetBuffer (uint16_t partition, ColumnIndex cid)
 get a buffer. Might be invalidated if rows are allocated or deallocated
 
Util::Blob SerializeInstance (RowId row) const
 Serialize a row into a blob.
 
void DeserializeInstance (Util::Blob const &data, RowId row)
 deserialize a blob into a row
 
PartitionNewPartition ()
 Create a new partition for this table. Adds it to the list of partitions and the vacancy list.
 

Static Public Member Functions

static RowId MigrateInstance (Table &src, RowId srcRow, Table &dst, bool defragment=true, std::function< void(Partition *, RowId, RowId)> const &moveCallback=nullptr)
 move instance from one table to another.
 
static RowId DuplicateInstance (Table const &src, RowId srcRow, Table &dst)
 duplicate instance from one row into destination table.
 
static void MigrateInstances (Table &src, Util::Array< RowId > const &srcRows, Table &dst, Util::FixedArray< RowId > &dstRows, bool defragment=true, std::function< void(Partition *, IndexT, IndexT)> const &moveCallback=nullptr)
 move n instances from one table to another.
 
static void DuplicateInstances (Table &src, Util::Array< RowId > const &srcRows, Table &dst, Util::FixedArray< RowId > &dstRows)
 duplicate instance from one row into destination table.
 

Public Attributes

Util::StringAtom name
 name of the table
 

Static Public Attributes

static constexpr Memory::HeapType HEAP_MEMORY_TYPE = Memory::HeapType::DefaultHeap
 allocation heap used for the column buffers
 

Private Types

using ColumnBuffer = void*
 

Private Member Functions

 Table ()=default
 
 ~Table ()
 

Private Attributes

TableSignature signature
 the signature of this table. Contains one bit set to true for every attribute that exists in the table.
 
TableId tid = TableId::Invalid()
 table identifier
 
uint32_t totalNumRows = 0
 sum of all rows in all partitions of this table,
 
PartitioncurrentPartition = nullptr
 Current partition that we'll be using when allocating data.
 
Util::Array< Partition * > partitions
 All partitions, even null partitions.
 
Util::Array< Partition * > freePartitions
 free partitions for recycling allocated partitions
 
Util::Array< uint16_t > nullPartitions
 indices to null partitions
 
PartitionfirstActivePartition = nullptr
 First partition that has entities. You can use this to iterate over all active partitions with entities by following the chain of partition->next.
 
uint16_t numActivePartitions = 0
 number of active partitions
 
Util::Array< AttributeIdattributes
 all attributes that this table has
 
Util::HashTable< AttributeId, IndexT, 32, 1 > columnRegistry
 maps attr id -> index in columns array
 

Friends

class Database
 

Member Typedef Documentation

◆ ColumnBuffer

using MemDb::Table::ColumnBuffer = void*
private

Constructor & Destructor Documentation

◆ Table()

MemDb::Table::Table ( )
privatedefault

◆ ~Table()

MemDb::Table::~Table ( )
private

Member Function Documentation

◆ AddAttribute()

ColumnIndex MemDb::Table::AddAttribute ( AttributeId attribute,
bool updateSignature = true )

Add an attribute to the table.

◆ AddRow()

RowId MemDb::Table::AddRow ( )

Add/Get a free row from the table.

◆ Clean()

void MemDb::Table::Clean ( )

Clean table. Does not deallocate anything; just sets the size of the table to zero.

◆ Defragment()

SizeT MemDb::Table::Defragment ( std::function< void(Partition *, RowId, RowId)> const & moveCallback)

Defragment table.

◆ DeserializeInstance()

void MemDb::Table::DeserializeInstance ( Util::Blob const & data,
RowId row )

deserialize a blob into a row

◆ DuplicateInstance()

RowId MemDb::Table::DuplicateInstance ( Table const & src,
RowId srcRow,
Table & dst )
static

duplicate instance from one row into destination table.

Returns
New index/row in destination table
Note
This might be destructive if the destination table is missing some of the source tables columns!

◆ DuplicateInstances()

void MemDb::Table::DuplicateInstances ( Table & src,
Util::Array< RowId > const & srcRows,
Table & dst,
Util::FixedArray< RowId > & dstRows )
static

duplicate instance from one row into destination table.

◆ GetAttributeId()

AttributeId MemDb::Table::GetAttributeId ( ColumnIndex columnIndex) const

Returns the attribute located in given column.

◆ GetAttributeIndex()

ColumnIndex MemDb::Table::GetAttributeIndex ( AttributeId attribute) const

Returns the index of the attribute or invalid if attribute is missing from table.

◆ GetAttributes()

Util::Array< AttributeId > const & MemDb::Table::GetAttributes ( ) const

Get the all descriptors for a table.

◆ GetBuffer()

void * MemDb::Table::GetBuffer ( uint16_t partition,
ColumnIndex cid )

get a buffer. Might be invalidated if rows are allocated or deallocated

◆ GetCurrentPartition()

Table::Partition * MemDb::Table::GetCurrentPartition ( )

Get current partition.

◆ GetFirstActivePartition()

Table::Partition * MemDb::Table::GetFirstActivePartition ( )

Get first active partition with entities.

◆ GetNumActivePartitions()

uint16_t MemDb::Table::GetNumActivePartitions ( ) const

Get number of partitions that contain entities.

◆ GetNumPartitions()

uint16_t MemDb::Table::GetNumPartitions ( ) const

Get number of partitions in table.

◆ GetNumRows()

SizeT MemDb::Table::GetNumRows ( ) const

Get total number of rows in a table.

◆ GetPartition()

Table::Partition * MemDb::Table::GetPartition ( uint16_t partitionId)

◆ GetSignature()

TableSignature const & MemDb::Table::GetSignature ( ) const

Get the table signature.

◆ GetValuePointer()

void * MemDb::Table::GetValuePointer ( ColumnIndex cid,
RowId row )

get a buffer. Might be invalidated if rows are allocated or deallocated

◆ HasAttribute()

bool MemDb::Table::HasAttribute ( AttributeId attribute) const

Check if a column exists in the table.

◆ MigrateInstance()

RowId MemDb::Table::MigrateInstance ( Table & src,
RowId srcRow,
Table & dst,
bool defragment = true,
std::function< void(Partition *, RowId, RowId)> const & moveCallback = nullptr )
static

move instance from one table to another.

◆ MigrateInstances()

void MemDb::Table::MigrateInstances ( Table & src,
Util::Array< RowId > const & srcRows,
Table & dst,
Util::FixedArray< RowId > & dstRows,
bool defragment = true,
std::function< void(Partition *, IndexT, IndexT)> const & moveCallback = nullptr )
static

move n instances from one table to another.

◆ NewPartition()

Table::Partition * MemDb::Table::NewPartition ( )

Create a new partition for this table. Adds it to the list of partitions and the vacancy list.

◆ RemoveRow()

void MemDb::Table::RemoveRow ( RowId row)

Deallocate a row from a table. This only frees the row for recycling. See Defragment.

◆ Reset()

void MemDb::Table::Reset ( )

Reset table. Deallocate all data.

◆ SerializeInstance()

Util::Blob MemDb::Table::SerializeInstance ( RowId row) const

Serialize a row into a blob.

◆ SetNumRows()

void MemDb::Table::SetNumRows ( SizeT value)

set total number of rows in a table. This does not allocate any memory or create instaces, thus should pretty much never be used.

◆ SetToDefault()

void MemDb::Table::SetToDefault ( RowId row)

Set all row values to default.

Friends And Related Symbol Documentation

◆ Database

friend class Database
friend

Member Data Documentation

◆ attributes

Util::Array<AttributeId> MemDb::Table::attributes
private

all attributes that this table has

◆ columnRegistry

Util::HashTable<AttributeId, IndexT, 32, 1> MemDb::Table::columnRegistry
private

maps attr id -> index in columns array

◆ currentPartition

Partition* MemDb::Table::currentPartition = nullptr
private

Current partition that we'll be using when allocating data.

◆ firstActivePartition

Partition* MemDb::Table::firstActivePartition = nullptr
private

First partition that has entities. You can use this to iterate over all active partitions with entities by following the chain of partition->next.

◆ freePartitions

Util::Array<Partition*> MemDb::Table::freePartitions
private

free partitions for recycling allocated partitions

◆ HEAP_MEMORY_TYPE

Memory::HeapType MemDb::Table::HEAP_MEMORY_TYPE = Memory::HeapType::DefaultHeap
staticconstexpr

allocation heap used for the column buffers

◆ name

Util::StringAtom MemDb::Table::name

name of the table

◆ nullPartitions

Util::Array<uint16_t> MemDb::Table::nullPartitions
private

indices to null partitions

◆ numActivePartitions

uint16_t MemDb::Table::numActivePartitions = 0
private

number of active partitions

◆ partitions

Util::Array<Partition*> MemDb::Table::partitions
private

All partitions, even null partitions.

◆ signature

TableSignature MemDb::Table::signature
private

the signature of this table. Contains one bit set to true for every attribute that exists in the table.

◆ tid

TableId MemDb::Table::tid = TableId::Invalid()
private

table identifier

◆ totalNumRows

uint32_t MemDb::Table::totalNumRows = 0
private

sum of all rows in all partitions of this table,


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