This is simple a first pass with mostly top level thoughts - I dig deeper later.
Suggest moving all functions to bst.c including
bst_init() size_t bst_encode() bst_decode(). By doing so,ENCODING_SIZE_T MAX_CONTENT_LENGTH BST_Nodeand the fields ofBSTmay be removed from the application view. The ap does not need to see them.
[Edit] I now seebst_init() size_t bst_encode() bst_decode()are only prototyped in bst.h - ignore that part of this suggestion. At first blush, the style looked like code, but it is only prototype.// BST.h typedef struct BST BST;` // BST.c struct BST { BST_Node *root; size_t node_count; int (*compare)(void *, void *); };I often use the prefix before functions like
BST_This()andBST_That(), but I would be consistent with the filename's case. Use BST.c withBST_This()or bst.c withbst_This().Need
#include <stdlib.h>forsize_tin bst.h. You might have caught that if in bst.c you included the standard headers after "bst.h". Suggest moving those after "bst.h". This prevents requiring users of bst.h to include certain headers files first.Large comment blocks before
bst_encodein bothbst.h bst.cis a maintenance liability. Suggest only one (inbst.h) a a reference inbst.ctobst.hto show you did not forget.Change compare function type to a
constversion.qsort()'s type shown for reference.int (*compare)(const void *, const void *); // qsort's --> int (*compar)(const void *, const void *);Maybe test for
compare()against NULL.To expand
compare()possibilities, add a compare state variable.Concerning
callback, allow that function to return anintand use a non-zero value to short-circuit the progress OR provide a state variable forcallback().
More later