feat(lsm): start store entry implementation

This commit is contained in:
Jef Roosens 2023-10-17 11:25:51 +02:00
parent 6938c29725
commit 115ee12f04
3 changed files with 143 additions and 0 deletions

View 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

View 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;
}