feat(lsm): possibly implemented trie insert

This commit is contained in:
Jef Roosens 2023-10-13 21:10:31 +02:00
parent 0548efda97
commit 622d644f25
Signed by: Jef Roosens
GPG key ID: B75D4F293C7052DB
8 changed files with 340 additions and 3 deletions

View file

@ -9,7 +9,8 @@ typedef enum lsm_error {
lsm_error_ok = 0,
lsm_error_failed_alloc = 1,
lsm_error_not_found = 2,
lsm_error_already_present = 3
lsm_error_already_present = 3,
lsm_error_null_value = 4
} lsm_error;
/*typedef struct lsm_string { */

View file

@ -48,4 +48,14 @@ lsm_error lsm_bt_insert(lsm_bt *bt, char key, void *data);
*/
lsm_error lsm_bt_remove(void **out, lsm_bt *bt, char key);
/**
* Replace the data at an existing key with new data, returning the old.
*
* @param out address to write old data pointer to
* @param bt binary tree to replace in
* @param key key to replace at
* @param data new data to store
*/
lsm_error lsm_bt_replace(void **out, lsm_bt *bt, char key, void *data);
#endif

View file

@ -57,4 +57,65 @@ void lsm_str_free(lsm_str *str);
*/
uint64_t lsm_str_len(lsm_str *str);
/**
* Return a pointer to the string's underlying char array. Note that this array
* will *not* neccessarily be null-terminatd.
*
* @param str string to return pointer for
*/
const char *lsm_str_ptr(lsm_str *str);
/**
* Returns the character at the specified position.
*
* @index index of character to return
*/
char lsm_str_char(lsm_str *str, uint64_t index);
/**
* Take a substring and copy it to a provided string object.
*
* @param out string to store new substring in. The contents of this string will
* be replaced.
* @param str string to take substring from
* @param start inclusive start index for the substring. If this is greater than
* or equal to the string's length, out will be a zero-length string.
* @param end exclusive end index for the substring
*/
lsm_error lsm_str_substr(lsm_str *out, lsm_str *str, uint64_t start,
uint64_t end);
/**
* Return the first index where s1 and s2 differ, starting at their respective
* offsets. If both strings are equal (or one is a prefix of the other), the
* result will be the length of the shortest string. The returned value is
* relative to the given offets.
*
* @param s1 string to compare
* @param s1_offset offset inside s1 to start comparing from
* @param s2 string to compare s1 to
* @param s2_offset offset inside s2 to start comparing from
*/
uint64_t lsm_str_cmp(lsm_str *s1, uint64_t s1_offset, lsm_str *s2,
uint64_t s2_offset);
/**
* Truncate a string in-place.
*
* @param s string to truncate
* @param new_len new length of the string. If new_len is >= the original
* length, this function does nothing.
*/
lsm_error lsm_str_truncate(lsm_str *s, uint64_t new_len);
/**
* Split s at the specified index, saving the second half the string in s2.
*
* @param s string to split
* @param s2 string to store second part of s
* @param index position to split string. If index is the length of s or
* greater, s2 will simply be an empty string.
*/
lsm_error lsm_str_split(lsm_str *s, lsm_str *s2, uint64_t index);
#endif