feat(lsm): start of library
This commit is contained in:
parent
98a1f5f671
commit
fd42b446a6
8 changed files with 314 additions and 1 deletions
67
lsm/include/lsm.h
Normal file
67
lsm/include/lsm.h
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
#ifndef LSM
|
||||
#define LSM
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define LSM_MAX_SKIP_SIZE 8
|
||||
|
||||
typedef enum lsm_error {
|
||||
lsm_error_ok = 0,
|
||||
lsm_error_failed_alloc = 1,
|
||||
lsm_error_not_found = 2
|
||||
} lsm_error;
|
||||
|
||||
/**
|
||||
* Represents a string (or really any kind of data) with a known length. Data
|
||||
* with length 8 or less is stored inside the pointer, and does not allocate
|
||||
* additional memory.
|
||||
*/
|
||||
typedef struct lsm_string {
|
||||
uint64_t len;
|
||||
union {
|
||||
void *ptr;
|
||||
char val[8];
|
||||
} str;
|
||||
} lsm_string;
|
||||
|
||||
/**
|
||||
* The type of an attribute. Each type is represented as a single bit of a
|
||||
* 32-bit integer, so they can be easily combined into a bitmap.
|
||||
*/
|
||||
typedef enum lsm_attr_type {
|
||||
lsm_attr_type_entry_type = 1 << 0
|
||||
} lsm_attr_type;
|
||||
|
||||
/**
|
||||
* A single attribute associated with an entry
|
||||
*/
|
||||
typedef struct lsm_attr {
|
||||
lsm_attr_type type;
|
||||
lsm_string str;
|
||||
} lsm_attr;
|
||||
|
||||
/**
|
||||
* Represents a collection of attributes for an entry. A collection can only
|
||||
* contain one of each attribute.
|
||||
*/
|
||||
typedef struct lsm_attr_list {
|
||||
uint64_t count;
|
||||
lsm_attr *items;
|
||||
uint32_t bitmap;
|
||||
} lsm_attr_list;
|
||||
|
||||
/**
|
||||
* An entry inside an LSM store
|
||||
*/
|
||||
typedef struct lsm_entry {
|
||||
lsm_string key;
|
||||
lsm_attr_list attrs;
|
||||
lsm_string data;
|
||||
} lsm_entry;
|
||||
|
||||
/**
|
||||
* A store of entries, which manages its data both in-memory and on disk.
|
||||
*/
|
||||
typedef struct lsm_store lsm_store;
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue