85 lines
2.0 KiB
C
85 lines
2.0 KiB
C
#ifndef LSM_STORE
|
|
#define LSM_STORE
|
|
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
|
|
#include "lsm.h"
|
|
#include "lsm/str.h"
|
|
|
|
/**
|
|
* The type of an entry attribute.
|
|
*
|
|
* Each type is represented as a single bit of an
|
|
* integer, so they can be easily combined into a bitmap.
|
|
*/
|
|
typedef enum lsm_attr_type : uint64_t {
|
|
lsm_attr_type_entry_type = 1 << 0,
|
|
lsm_attr_type_content_type = 1 << 1
|
|
} lsm_attr_type;
|
|
|
|
/**
|
|
* An entry inside an LSM store.
|
|
*
|
|
* Each entry consists of the key it's stored behind, zero or more attributes
|
|
* (metadata) and a data field. The data field can be stored on disk or
|
|
* in-memory, depending on the size.
|
|
*/
|
|
typedef struct lsm_entry lsm_entry;
|
|
|
|
/**
|
|
* Allocate and initialize a new lsm_entry object.
|
|
*
|
|
* @param ptr where to store newly allocated pointer
|
|
*/
|
|
lsm_error lsm_entry_init(lsm_entry **ptr);
|
|
|
|
/**
|
|
* Deallocate an existing lsm_entry object.
|
|
*
|
|
* @param entry object to deallocate
|
|
*/
|
|
void lsm_entry_free(lsm_entry *entry);
|
|
|
|
/**
|
|
* Checks whether the entry has an attribute with the specified type.
|
|
*
|
|
* @param entry entry to check
|
|
* @param type type of attribute to check for
|
|
*/
|
|
bool lsm_entry_attr_present(lsm_entry *entry, lsm_attr_type type);
|
|
|
|
/**
|
|
* Retrieve the contents of an attribute from an entry, if present
|
|
*
|
|
* @param out where to store pointer to attribute data
|
|
* @param entry entry to search for
|
|
* @param type type of attribute to return
|
|
*/
|
|
lsm_error lsm_entry_attr_get(lsm_str **out, lsm_entry *entry,
|
|
lsm_attr_type type);
|
|
|
|
/**
|
|
* A store consisting of LSM entries.
|
|
*
|
|
* A store manages both an in-memory data structure for quick lookup, and a
|
|
* database file for persistent storage of the contained entries.
|
|
*/
|
|
typedef struct lsm_store lsm_store;
|
|
|
|
/**
|
|
* Allocate and initialize a new lsm_store object.
|
|
*
|
|
* @param ptr where to store newly allocated pointer
|
|
*/
|
|
lsm_error lsm_store_init(lsm_store **ptr);
|
|
|
|
/**
|
|
* Dealocate an existing lsm_store object.
|
|
*
|
|
* @param store object to deallocate
|
|
*/
|
|
void lsm_store_free(lsm_store *store);
|
|
|
|
#endif
|