lander/lsm/src/store/lsm_store_entry.c

38 lines
796 B
C
Raw Normal View History

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