WiscKey Database
Embedded LSM-Tree Key-Value Database
Loading...
Searching...
No Matches
memtable.h File Reference

In-memory table of the records that have been modified most recently. More...

#include <stdint.h>
#include <stdlib.h>
Include dependency graph for memtable.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  MemTableRecord
 Single Record in the MemTable. More...
 
struct  MemTable
 MemTable of the Database. More...
 

Macros

#define MEMTABLE_SIZE   1024
 Max number of MemTableRecords in a MemTable.
 

Functions

struct MemTableMemTable_new ()
 Creates a new empty MemTable.
 
struct MemTableRecordMemTable_get (const struct MemTable *memtable, const char *key, size_t key_len)
 Gets a MemTableRecord from a MemTable by key.
 
void MemTable_set (struct MemTable *memtable, const char *key, size_t key_len, int64_t value_loc)
 Sets a key-value pair in a MemTable.
 
void MemTable_delete (struct MemTable *memtable, const char *key, size_t key_len)
 Deletes a record from a MemTable.
 
void MemTable_free (struct MemTable *memtable)
 Frees a MemTable and its records.
 

Detailed Description

In-memory table of the records that have been modified most recently.

Author
Adam Comer adamb.nosp@m.come.nosp@m.r@gma.nosp@m.il.c.nosp@m.om
Date
May 15, 2020

Function Documentation

◆ MemTable_delete()

void MemTable_delete ( struct MemTable * memtable,
const char * key,
size_t key_len )

Deletes a record from a MemTable.

This function uses binary search for a runtime of O(log(n)).

Note: This function will set a tombstone to propagate the delete into the SSTables.

Parameters
memtableThe MemTable to delete a record from.
keyThe key to delete.
key_lenThe length of the key.

◆ MemTable_free()

void MemTable_free ( struct MemTable * memtable)

Frees a MemTable and its records.

Note: This function will free all the MemTableRecords plus their keys in this MemTable.

Parameters
memtableThe MemTable to free.

◆ MemTable_get()

struct MemTableRecord * MemTable_get ( const struct MemTable * memtable,
const char * key,
size_t key_len )

Gets a MemTableRecord from a MemTable by key.

This function will return NULL if none of the records in the MemTable.

This function uses binary search for a runtime of O(log(n)).

Parameters
memtableThe MemTable to search.
keyThe key to search the MemTable with.
key_lenThe length of the key.
Returns
A MemTableRecord if the record exists or NULL if it doesn't not exist.

◆ MemTable_new()

struct MemTable * MemTable_new ( )

Creates a new empty MemTable.

Note: Free this MemTable with MemTable_free.

Returns
A new empty MemTable.

◆ MemTable_set()

void MemTable_set ( struct MemTable * memtable,
const char * key,
size_t key_len,
int64_t value_loc )

Sets a key-value pair in a MemTable.

This function uses binary search for a runtime of O(log(n)).

Parameters
memtableThe MemTable to set a value to.
keyThe key to set this value for.
key_lenThe length of the key.
value_locThe seek location to the value in the ValueLog.