JLospinoso / forest

Forest is an open source, template library of tree data structures written in C++11.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

forest logo

CircleCI

Forest is an open source, template library of tree data structures written in C++11.

Installation

Linux / macOS

$ git clone https://github.com/xorz57/forest.git
$ cd forest
$ mkdir build
$ cd build
$ cmake ..
$ make install

Example Code

Forest is best explained through examples. The following source code generates a red black tree, inserts 7 nodes and then performs an in order traversal.

#include <forest/red_black_tree.h>

int main() {
        // Generate a binary search tree for nodes of integer keys and values
        forest::red_black_tree <int, int> red_black_tree;

        // Insert 7 nodes in the form of a (key, value) pair
        red_black_tree.insert(4,0);
        red_black_tree.insert(2,0);
        red_black_tree.insert(90,0);
        red_black_tree.insert(3,100);
        red_black_tree.insert(0,0);
        red_black_tree.insert(14,0);
        red_black_tree.insert(45,0);

        // Perform an in order traversal
        red_black_tree.in_order_traversal();

        // Generate a .dot file representing the Red Black Tree
        red_black_tree.graphviz("red_black_tree.dot");

        return 0;
}

Graph Visualization using Graphviz

Forest provides an easy way to visualize tree data structures using the graphviz member function. When this function is called, a DOT file describing the data structure graph is created. In order to be able to generate an image of the graph you must install Graphviz. The generated DOT file can be feed to the dot tool (provided by Graphviz) which in turn will generate an image for the graph.

$ dot red_black_tree.dot -Tpng > red_black_tree.png

This is the graph visualization of the above example code, generated with the dot tool (provided by Graphviz).

Red Black Tree Graph

Refer to the Quick Start Guide page for further information and examples.

About

Forest is an open source, template library of tree data structures written in C++11.

License:MIT License


Languages

Language:C++ 99.9%Language:CMake 0.1%