https://github.com/tasxatzial/leaf-search-trees
Leaf-oriented binary search trees
https://github.com/tasxatzial/leaf-search-trees
Last synced: 1 day ago
JSON representation
Leaf-oriented binary search trees
- Host: GitHub
- URL: https://github.com/tasxatzial/leaf-search-trees
- Owner: tasxatzial
- License: mit
- Created: 2022-06-20T14:45:48.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-10-29T01:24:26.000Z (almost 2 years ago)
- Last Synced: 2025-03-02T15:50:00.407Z (8 months ago)
- Language: C
- Homepage:
- Size: 331 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Leaf-oriented binary search trees
A data structure that can be used for storing dictionaries, which are sorted collections of (key, value) pairs, sorted by key.
This version supports (key, value) pairs that have type (char*, void*).
The following functions are provided:
* lbst_create(): Create an empty dictionary.
* lbst_is_empty(d): Check whether the dictionary is empty.
* lbst_insert(d, key, value): Insert (key, value). If key exists, update its value.
* lbst_delete(d, key): Delete key.
* lbst_lookup(d, key): Get the value associated with key.
* lbst_print(d): Print the dictionary.
* lbst_clear(d): Clear the dictionary.
* lbst_free(d): Delete the dictionary.
* lbst_range_query(d, first, last): Print all pairs with key between first and last (inclusive).## Implementation
The dictionary is defined as an [opaque data type](https://en.wikipedia.org/wiki/Opaque_data_type). The public interface is defined in [lbst.h](src/lbst.h).
C-strings are supported as keys and are stored directly in the dictionary. Values can be of any type, therefore they should already be stored in a different data structure.
Time complexity is O(tree_height) for 'insert', 'delete', 'lookup' and O(tree_height + number of keys) for 'range_query'. Details can be found in [lbst.md](lbst.md).
For a simpler version of the library that supports only (int, int) pairs, see [leaf-search-tree-int](https://github.com/tasxatzial/leaf-search-tree-int).
## Compile
Build the library (functions declared in [lbst.h](src/lbst.h)):
```bash
make lbst.o
```## Demo
Using the library is demonstrated in [main.c](src/main.c).
Build:
```bash
make lbst_demo
```Run:
```bash
./lbst_demo
```## Profiling
'lbst_demo' has been tested for memory leaks with [valgrind](https://valgrind.org/) and [AddressSanitizer](https://github.com/google/sanitizers/wiki/AddressSanitizer).