#include #include "lsm.h" #include "lsm_store_node.h" lsm_error lsm_store_inode_init(lsm_store_inode **ptr, const char c) { lsm_store_inode *node = calloc(1, sizeof(lsm_store_inode)); if (node == NULL) { return lsm_error_failed_alloc; } node->key = c; *ptr = node; return lsm_error_ok; } lsm_error lsm_store_node_init(lsm_store_node **ptr) { lsm_store_node *node = calloc(1, sizeof(lsm_store_node)); if (node == NULL) { return lsm_error_failed_alloc; } *ptr = node; return lsm_error_ok; } lsm_error lsm_store_node_search(lsm_store_node **out_ptr, lsm_store_node *node, const char c) { if (node->size == 0) { return lsm_error_not_found; } lsm_store_inode *parent = node->root; lsm_store_inode *child; lsm_store_node *out = NULL; while (1) { if (parent->key == c) { out = parent->next; break; } child = (c < parent->key) ? parent->left : parent->right; if (child == NULL) { break; } parent = child; }; if (out == NULL) { return lsm_error_not_found; } *out_ptr = out; return lsm_error_ok; }