Red-Black Trees are binary search trees satisfying the following conditions:
- every node is either red or black;
- the root is black;
- every leaf (NIL) is black;
- if a node is red, then its children are black;
- for each node x, all the simple paths from x to descendant leaves contain the same number of black nodes.
Thanks to the mentioned properties, it is possible to insert, delete, and search a value in a red-black tree in time O(log n) [1].
[1] Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. Introduction to Algorithms. The MIT Press, 2nd edition, 2001.
Current folder contains a simple implementation of a templated Red-Black Tree class, together with its const-iterator.
-
bmkfolder includes abmk.cppfile to run a small experiment aimed at timing the performance of the find() method on our Red-Black Tree naive implementation, against the std::map and std::unordered_map containers' same method. The .txt output is then used as a source for thebmk_times_plot.pyin order to generate the two .png pictures present in the folder. More detailed description available within the bmk.cpp file. -
doxygenfolder includes adoxy_configfile with (custom) options and parameters chosen for automatically creating documentation for the classes. Upon generation, all documentation will be available in bothhtmlandlatexsubfolders. -
includefolder is composed of 3 header files:Node.hpp: declarations and implementation of members and methods for Node class;RBT.hpp: declarations and implementation of members and methods for RBTree class;RBT_iterator.hpp: declarations and implementation of members and methods for RBTree's const_iterator subclass.
-
testfolder includes both atests.cppfile containing the official unit-tests for the above mentioned classes -all performed with the Boost.Test framework-, paired with an unofficialmain.ccfile, aimed at showing how to use most part of classes' features.
Attached Makefile is used to help in the compilation of project's files:
-
makecommand creates sequentially abuildand abinfolder containing respectively the object (.o) and executable (.x) files for tests.cpp and bmk.cpp. All generated executable files are then ready for use into the bin folder. -
make cleancommand clears the entire build directory, all the executables present into the bin directory and -if already created- all the documentation within the doxygen folder. -
make clearscommand clears the screen of the Terminal in use from the results coming from previously inserted commands and from the runs of the excecutables. -
make docsgenerates documentation for the code inside the doxygen folder. -
make formatautomatically formats all the code files present in the include and test directories following the clang-format.
