chore(lsm): some refactoring
All checks were successful
ci/woodpecker/push/docker Pipeline was successful

This commit is contained in:
Jef Roosens 2023-11-16 21:52:20 +01:00
parent e3aad2b5e4
commit 881f2defbe
Signed by: Jef Roosens
GPG key ID: B75D4F293C7052DB
9 changed files with 60 additions and 76 deletions

View file

@ -10,6 +10,15 @@
return res; \
}
#define LSM_RES2(x, e) \
{ \
lsm_error res = x; \
if (res != lsm_error_ok) { \
e; \
return res; \
} \
}
typedef enum lsm_error {
lsm_error_ok = 0,
lsm_error_failed_alloc = 1,

View file

@ -37,7 +37,7 @@ uint64_t lsm_bt_size(const lsm_bt *bt);
* @param bt binary tree to search
* @param key key to search
*/
lsm_error lsm_bt_search(void **out, lsm_bt *bt, char key);
lsm_error lsm_bt_search(void **out, const lsm_bt *bt, char key);
/**
* Insert a new data value into the tree with the given key.

View file

@ -143,7 +143,7 @@ void lsm_store_free(lsm_store *store);
* @param key key to search
*/
lsm_error lsm_store_open_read(lsm_entry_handle **out, lsm_store *store,
lsm_str *key);
const lsm_str *key);
/**
* Open a write handle to the given entry. This handle should only be used for
@ -155,7 +155,7 @@ lsm_error lsm_store_open_read(lsm_entry_handle **out, lsm_store *store,
* @param key key to search
*/
lsm_error lsm_store_open_write(lsm_entry_handle **out, lsm_store *store,
lsm_str *key);
const lsm_str *key);
/**
* Close an open entry handle.
@ -193,7 +193,7 @@ void lsm_entry_remove(lsm_entry_handle *handle);
* @param entry entry to append data to
* @param data data to append
*/
lsm_error lsm_entry_data_append(lsm_entry_handle *handle, lsm_str *data);
lsm_error lsm_entry_data_append(lsm_entry_handle *handle, const lsm_str *data);
/**
* Same as `lsm_entry_data_append`, except that it takes a direct char array.

View file

@ -107,14 +107,14 @@ uint64_t lsm_str_len(const lsm_str *str);
*
* @param str string to return pointer for
*/
const char *lsm_str_ptr(lsm_str *str);
const char *lsm_str_ptr(const 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);
char lsm_str_char(const lsm_str *str, uint64_t index);
/**
* Take a substring and copy it to a provided string object.
@ -127,7 +127,7 @@ char lsm_str_char(lsm_str *str, uint64_t index);
* 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,
lsm_error lsm_str_substr(lsm_str *out, const lsm_str *str, uint64_t start,
uint64_t end);
/**
@ -141,7 +141,7 @@ lsm_error lsm_str_substr(lsm_str *out, lsm_str *str, uint64_t start,
* @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 lsm_str_cmp(const lsm_str *s1, uint64_t s1_offset, const lsm_str *s2,
uint64_t s2_offset);
/**
@ -151,7 +151,7 @@ uint64_t lsm_str_cmp(lsm_str *s1, uint64_t s1_offset, lsm_str *s2,
* @param s2 second string to compare
* @return true if their values are equal, false otherwise
*/
bool lsm_str_eq(lsm_str *s1, lsm_str *s2);
bool lsm_str_eq(const lsm_str *s1, const lsm_str *s2);
/**
* Truncate an already initialized string in-place.

View file

@ -30,16 +30,16 @@ void lsm_trie_free(lsm_trie *trie);
* @param key key to insert data with
* @param data data to insert
*/
lsm_error lsm_trie_insert(lsm_trie *trie, lsm_str *key, void *data);
lsm_error lsm_trie_insert(lsm_trie *trie, const lsm_str *key, void *data);
/**
* Search for an element in the trie.
*
* @param out where to store data opinter, if present
* @param out where to store data pointer, if present
* @param trie trie to search in
* @param key key to search with
*/
lsm_error lsm_trie_search(void **data, lsm_trie *trie, lsm_str *key);
lsm_error lsm_trie_search(void **out, const lsm_trie *trie, const lsm_str *key);
/**
* Remove an element from the trie.
@ -48,7 +48,7 @@ lsm_error lsm_trie_search(void **data, lsm_trie *trie, lsm_str *key);
* @param trie trie to remove from
* @param key key to remove
*/
lsm_error lsm_trie_remove(void **data, lsm_trie *trie, lsm_str *key);
lsm_error lsm_trie_remove(void **out, lsm_trie *trie, const lsm_str *key);
/**
* Return the size of a trie