feat(lsm): added trie search

This commit is contained in:
Jef Roosens 2023-10-13 22:08:06 +02:00
parent 622d644f25
commit 87000e8f73
Signed by: Jef Roosens
GPG key ID: B75D4F293C7052DB
5 changed files with 124 additions and 6 deletions

View file

@ -44,6 +44,33 @@ lsm_error lsm_str_init(lsm_str **ptr, char *s) {
return lsm_error_ok;
}
lsm_error lsm_str_init_copy(lsm_str **ptr, char *s) {
lsm_str *str = calloc(1, sizeof(lsm_str));
if (str == NULL) {
return lsm_error_failed_alloc;
}
str->len = strlen(s);
if (str->len <= 8) {
memcpy(str->data.val, s, str->len);
} else {
char *buf = malloc(str->len * sizeof(char));
if (buf == NULL) {
return lsm_error_failed_alloc;
}
memcpy(buf, s, str->len);
str->data.ptr = buf;
}
*ptr = str;
return lsm_error_ok;
}
void lsm_str_zero(lsm_str *str) {
if (str->len > 8) {
free(str->data.ptr);