feat(lsm): start store entry implementation
This commit is contained in:
parent
6938c29725
commit
115ee12f04
3 changed files with 143 additions and 0 deletions
22
lsm/src/_include/lsm/store_internal.h
Normal file
22
lsm/src/_include/lsm/store_internal.h
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#ifndef LSM_STORE_INTERNAL
|
||||
#define LSM_STORE_INTERNAL
|
||||
|
||||
#include "lsm/store.h"
|
||||
#include "lsm/str_internal.h"
|
||||
|
||||
typedef struct lsm_attr {
|
||||
lsm_attr_type type;
|
||||
lsm_str str;
|
||||
} lsm_attr;
|
||||
|
||||
struct lsm_entry {
|
||||
lsm_str key;
|
||||
struct {
|
||||
uint64_t count;
|
||||
uint64_t bitmap;
|
||||
lsm_attr *items;
|
||||
} attrs;
|
||||
lsm_str data;
|
||||
};
|
||||
|
||||
#endif
|
||||
37
lsm/src/store/lsm_store_entry.c
Normal file
37
lsm/src/store/lsm_store_entry.c
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#include "lsm.h"
|
||||
#include "lsm/store_internal.h"
|
||||
|
||||
lsm_error lsm_entry_init(lsm_entry **ptr) {
|
||||
lsm_entry *entry = calloc(1, sizeof(lsm_entry));
|
||||
|
||||
if (entry == NULL) {
|
||||
return lsm_error_failed_alloc;
|
||||
}
|
||||
|
||||
*ptr = entry;
|
||||
|
||||
return lsm_error_ok;
|
||||
}
|
||||
|
||||
bool lsm_entry_attr_present(lsm_entry *entry, lsm_attr_type type) {
|
||||
return (entry->attrs.bitmap & type) != 0;
|
||||
}
|
||||
|
||||
lsm_error lsm_entry_attr_get(lsm_str **out, lsm_entry *entry,
|
||||
lsm_attr_type type) {
|
||||
if (!lsm_entry_attr_present(entry, type)) {
|
||||
return lsm_error_not_found;
|
||||
}
|
||||
|
||||
for (uint64_t i = 0; i < entry->attrs.count; i++) {
|
||||
if (entry->attrs.items[i].type == type) {
|
||||
*out = &entry->attrs.items[i].str;
|
||||
|
||||
return lsm_error_ok;
|
||||
}
|
||||
}
|
||||
|
||||
return lsm_error_not_found;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue