This library offers a versatile B-Tree implementation in C, ideal for efficient key-value storage and retrieval. It supports various key types, making it suitable for a wide range of applications.
Compile the library with the following command:
makeThis example demonstrates how to add an entry to the B-Tree and retrieve it.
btree_t*btree=new_btree();
add_entry(btree, "entry_1", sizeof("entry_1"), "value_1", sizeof("value_1"));
value_t*value=find_entry(btree, "entry_1", sizeof("entry_1"));
// Use 'value' as neededfree_tree(&btree);Here's how to add multiple entries and list them.
btree_t*btree=new_btree();
add_entry(btree, "entry_1", sizeof("entry_1"), "value_1", sizeof("value_1"));
// ... Add more entriesentry_list_t*list=list_entries(btree);
// Iterate over 'list' to access entriesfree_entry_list(&list);
free_tree(&btree);This example shows how to remove an entry from the B-Tree.
btree_t*btree=new_btree();
add_entry(btree, "entry_1", sizeof("entry_1"), "value_1", sizeof("value_1"));
remove_entry(btree, "entry_1", sizeof("entry_1"));
// 'entry_1' is now removed from the B-Treefree_tree(&btree);The B-Tree can handle various key types. Here's an example using an integer key.
btree_t*btree=new_btree();
uint32_tint_key=123;
add_entry(btree, &int_key, sizeof(int_key), "value_123", sizeof("value_123"));
value_t*value=find_entry(btree, &int_key, sizeof(int_key));
// Use 'value' as neededfree_tree(&btree);You can also use custom structs as keys or values.
typedefstructcustom_key {
uint32_tkey_part1;
uint32_tkey_part2;
} custom_key_t;
btree_t*btree=new_btree();
custom_key_tmy_key= {1, 2};
add_entry(btree, &my_key, sizeof(my_key), "custom_value", sizeof("custom_value"));
value_t*value=find_entry(btree, &my_key, sizeof(my_key));
// Use 'value' as neededfree_tree(&btree);Contributions to improve this library are welcome. Feel free to submit pull requests or raise issues.