vkdb
A time series database engine in C++.
Loading...
Searching...
No Matches
vkdb::MemTable< TValue > Class Template Reference

In-memory table for storing key-value pairs. More...

#include <mem_table.h>

Public Types

using key_type = TimeSeriesKey
 
using mapped_type = std::optional<TValue>
 
using value_type = std::pair<const key_type, mapped_type>
 
using size_type = uint64_t
 
using table_type = std::map<const key_type, mapped_type>
 

Public Member Functions

 MemTable () noexcept=default
 Construct a new MemTable object.
 
 MemTable (table_type &&entries) noexcept
 Construct a new MemTable object from a map of entries.
 
 MemTable (MemTable &&) noexcept=default
 Move-construct a MemTable object.
 
MemTableoperator= (MemTable &&) noexcept=default
 Move-assign a MemTable object.
 
 MemTable (const MemTable &)=delete
 Deleted copy constructor.
 
MemTableoperator= (const MemTable &)=delete
 Deleted copy assignment operator.
 
 ~MemTable () noexcept=default
 Destroy the MemTable object.
 
void put (const key_type &key, const mapped_type &value)
 Inserts or updates a key-value pair in the table.
 
bool contains (const key_type &key) const noexcept
 Checks if the table contains a key.
 
mapped_type get (const key_type &key) const
 Retrieves the value associated with a key.
 
std::vector< value_type > getRange (const key_type &start, const key_type &end) const
 Retrieves a range of key-value pairs.
 
void clear () noexcept
 Clears the table.
 
table_type table () const noexcept
 Returns the table.
 
size_type size () const noexcept
 Returns the size of the table.
 
bool empty () const noexcept
 Checks if the table is empty.
 
std::string str () const noexcept
 Converts the table to a string representation.
 

Static Public Member Functions

static void fromString (const std::string &str, MemTable &table)
 Converts a string representation to a table.
 

Static Public Attributes

static constexpr size_type C0_LAYER_SSTABLE_MAX_ENTRIES {100'000}
 

Detailed Description

template<ArithmeticNoCVRefQuals TValue>
class vkdb::MemTable< TValue >

In-memory table for storing key-value pairs.

Template Parameters
TValueThe type of the value to be stored in the table.

Definition at line 17 of file mem_table.h.

Member Typedef Documentation

◆ key_type

template<ArithmeticNoCVRefQuals TValue>
using vkdb::MemTable< TValue >::key_type = TimeSeriesKey

Definition at line 19 of file mem_table.h.

◆ mapped_type

template<ArithmeticNoCVRefQuals TValue>
using vkdb::MemTable< TValue >::mapped_type = std::optional<TValue>

Definition at line 20 of file mem_table.h.

◆ size_type

template<ArithmeticNoCVRefQuals TValue>
using vkdb::MemTable< TValue >::size_type = uint64_t

Definition at line 22 of file mem_table.h.

◆ table_type

template<ArithmeticNoCVRefQuals TValue>
using vkdb::MemTable< TValue >::table_type = std::map<const key_type, mapped_type>

Definition at line 23 of file mem_table.h.

◆ value_type

template<ArithmeticNoCVRefQuals TValue>
using vkdb::MemTable< TValue >::value_type = std::pair<const key_type, mapped_type>

Definition at line 21 of file mem_table.h.

Constructor & Destructor Documentation

◆ MemTable()

template<ArithmeticNoCVRefQuals TValue>
vkdb::MemTable< TValue >::MemTable ( table_type && entries)
inlinenoexcept

Construct a new MemTable object from a map of entries.

Parameters
entriesThe entries to initialise the table with.

Definition at line 37 of file mem_table.h.

Member Function Documentation

◆ clear()

template<ArithmeticNoCVRefQuals TValue>
void vkdb::MemTable< TValue >::clear ( )
inlinenoexcept

Clears the table.

Definition at line 142 of file mem_table.h.

◆ contains()

template<ArithmeticNoCVRefQuals TValue>
bool vkdb::MemTable< TValue >::contains ( const key_type & key) const
inlinenodiscardnoexcept

Checks if the table contains a key.

Parameters
keyThe key to check.
Returns
true If the key is in the table.
false Otherwise.

Definition at line 87 of file mem_table.h.

◆ empty()

template<ArithmeticNoCVRefQuals TValue>
bool vkdb::MemTable< TValue >::empty ( ) const
inlinenodiscardnoexcept

Checks if the table is empty.

Returns
true If the table is empty.
false Otherwise.

Definition at line 172 of file mem_table.h.

◆ fromString()

template<ArithmeticNoCVRefQuals TValue>
static void vkdb::MemTable< TValue >::fromString ( const std::string & str,
MemTable< TValue > & table )
inlinestatic

Converts a string representation to a table.

Parameters
strThe string representation of the table.
tableThe table to populate.
Exceptions
std::exceptionIf converting any string to entry fails.

Definition at line 198 of file mem_table.h.

◆ get()

template<ArithmeticNoCVRefQuals TValue>
mapped_type vkdb::MemTable< TValue >::get ( const key_type & key) const
inlinenodiscard

Retrieves the value associated with a key.

Parameters
keyThe key to retrieve the value for.
Returns
mapped_type The value associated with the key.
Exceptions
std::invalid_argumentIf the key is not in the memtable.

Definition at line 99 of file mem_table.h.

◆ getRange()

template<ArithmeticNoCVRefQuals TValue>
std::vector< value_type > vkdb::MemTable< TValue >::getRange ( const key_type & start,
const key_type & end ) const
inlinenodiscard

Retrieves a range of key-value pairs.

Parameters
startThe start key of the range.
endThe end key of the range.
Returns
std::vector<value_type> A vector of key-value pairs in the specified range.
Exceptions
std::exceptionIf getting the range fails.

Definition at line 123 of file mem_table.h.

◆ operator=()

template<ArithmeticNoCVRefQuals TValue>
MemTable & vkdb::MemTable< TValue >::operator= ( MemTable< TValue > && )
defaultnoexcept

Move-assign a MemTable object.

Returns
MemTable& Reference to the moved MemTable.

◆ put()

template<ArithmeticNoCVRefQuals TValue>
void vkdb::MemTable< TValue >::put ( const key_type & key,
const mapped_type & value )
inline

Inserts or updates a key-value pair in the table.

Parameters
keyThe key to insert or update.
valueThe value to associate with the key.
Exceptions
std::exceptionIf inserting or updating the key-value pair fails.

Definition at line 75 of file mem_table.h.

◆ size()

template<ArithmeticNoCVRefQuals TValue>
size_type vkdb::MemTable< TValue >::size ( ) const
inlinenodiscardnoexcept

Returns the size of the table.

Returns
size_type The size of the table.

Definition at line 162 of file mem_table.h.

◆ str()

template<ArithmeticNoCVRefQuals TValue>
std::string vkdb::MemTable< TValue >::str ( ) const
inlinenodiscardnoexcept

Converts the table to a string representation.

Returns
std::string The string representation of the table.

Definition at line 181 of file mem_table.h.

◆ table()

template<ArithmeticNoCVRefQuals TValue>
table_type vkdb::MemTable< TValue >::table ( ) const
inlinenodiscardnoexcept

Returns the table.

Returns
table_type The table.

Definition at line 153 of file mem_table.h.

Member Data Documentation

◆ C0_LAYER_SSTABLE_MAX_ENTRIES

template<ArithmeticNoCVRefQuals TValue>
size_type vkdb::MemTable< TValue >::C0_LAYER_SSTABLE_MAX_ENTRIES {100'000}
staticconstexpr

Definition at line 25 of file mem_table.h.


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