All Projects → kpeeters → tree.hh

kpeeters / tree.hh

Licence: other
An STL-like C++ header-only tree library

Programming Languages

C++
36643 projects - #6 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to tree.hh

ctl
My variant of the C Template Library
Stars: ✭ 105 (+32.91%)
Mutual labels:  tree, stl-containers
react
Basic Primitives Diagrams for React. Data visualization components library that implements organizational chart and multi-parent dependency diagrams.
Stars: ✭ 15 (-81.01%)
Mutual labels:  tree
GenealogyTreeInGit
Convert family trees from gedcom format to list of git commands that can be executed to build a family git repository
Stars: ✭ 15 (-81.01%)
Mutual labels:  tree
ddrt
An elixir implementation of Rtree, optimized for fast updates.
Stars: ✭ 38 (-51.9%)
Mutual labels:  tree
gb merkle trees
General balanced binary Merkle trees for Erlang
Stars: ✭ 25 (-68.35%)
Mutual labels:  tree
twtree
a highly customizable tree component for vue 2
Stars: ✭ 27 (-65.82%)
Mutual labels:  tree
Tree-Style-History
Not only show browser history in tree style. 不止用树状形式展示浏览器历史 (For Edge / Chromium / Chrome)
Stars: ✭ 124 (+56.96%)
Mutual labels:  tree
AlgoDaily
just for fun
Stars: ✭ 118 (+49.37%)
Mutual labels:  tree
myleetcode
♨️ Detailed Java & Python solution of LeetCode.
Stars: ✭ 34 (-56.96%)
Mutual labels:  tree
InterviewBit
Collection of solution for problems on InterviewBit
Stars: ✭ 77 (-2.53%)
Mutual labels:  tree
laravel-nova-order-nestedset-field
Laravel Nova field that make your resources orderable
Stars: ✭ 21 (-73.42%)
Mutual labels:  tree
geo-tree
High performance library for geographical map-related operations
Stars: ✭ 51 (-35.44%)
Mutual labels:  tree
treap
A thread-safe, persistent Treap (tree + heap) for ordered key-value mapping and priority sorting.
Stars: ✭ 23 (-70.89%)
Mutual labels:  tree
vue3-tree
A tree library for Vue 3
Stars: ✭ 41 (-48.1%)
Mutual labels:  tree
pscircle
https://gitlab.com/mildlyparallel/pscircle visualizes Linux processes in a form of radial tree.
Stars: ✭ 33 (-58.23%)
Mutual labels:  tree
Unity-Visual-Behavior-Tree
Reactive Visual Scripting Behavior Tree Tool for Unity 2018.x+
Stars: ✭ 36 (-54.43%)
Mutual labels:  tree
Algorithm-Data-Structures-Python
Various useful data structures in Python
Stars: ✭ 34 (-56.96%)
Mutual labels:  tree
react-treefold
A renderless tree component for your hierarchical React views
Stars: ✭ 37 (-53.16%)
Mutual labels:  tree
vue-sortable-tree
vue tree draggable, drag item sort
Stars: ✭ 87 (+10.13%)
Mutual labels:  tree
wlui
wl-ui 精美易用的前端复杂组件解决方案。Beautiful and easy-to-use front-end complex component solution
Stars: ✭ 32 (-59.49%)
Mutual labels:  tree

tree.hh: an STL-like C++ tree class

by Kasper Peeters <[email protected]>

The tree.hh library for C++ provides an STL-like container class for n-ary trees, templated over the data stored at the nodes. Various types of iterators are provided (post-order, pre-order, and others). Where possible the access methods are compatible with the STL or alternative algorithms are available.

The library should work with any C++11 compiler, and has been used and tested on all major platforms (Linux, Windows, macOS, Android, iOS).

The library is available under the terms of the GNU General Public License version 2 or 3.

What you need

The tree.hh is header-only; you only need to copy the src/tree.hh header file into your project and you are good to go.

Then scan the example below and consult the documentation.

Sample use

The following is a small sample program to illustrate how tree.hh is used:

#include <algorithm>
#include <string>
#include <iostream>
#include "tree.hh"

using namespace std;

int main(int, char **)
   {
   tree<string> tr;
   tree<string>::iterator top, one, two, loc, banana;

   top=tr.begin();
   one=tr.insert(top, "one");
   two=tr.append_child(one, "two");
   tr.append_child(two, "apple");
   banana=tr.append_child(two, "banana");
   tr.append_child(banana,"cherry");
   tr.append_child(two, "peach");
   tr.append_child(one,"three");

   loc=find(tr.begin(), tr.end(), "two");
   if(loc!=tr.end()) {
   tree<string>::sibling_iterator sib=tr.begin(loc);
   while(sib!=tr.end(loc)) {
     cout << (*sib) << endl;
     ++sib;
     }
   cout << endl;
   tree<string>::iterator sib2=tr.begin(loc);
   tree<string>::iterator end2=tr.end(loc);
   while(sib2!=end2) {
     for(int i=0; i<tr.depth(sib2)-2; ++i)
        cout << " ";
     cout << (*sib2) << endl;
     ++sib2;
     }
   }
}

The output of this program is:

apple
banana
peach

apple
banana
 cherry
peach

Note that this example only has one element at the top of the tree (in this case that is the node containing one) but it is possible to have an arbitary number of such elements (then the tree is more like a "bush"). Observe the way in which the two types of iterators work. The first block of output, obtained using the sibling_iterator, only displays the children directly below two. The second block iterates over all children at any depth below two. In the second output block, the depth member has been used to determine the distance of a given node to the root of the tree.

Structure

https://raw.githubusercontent.com/kpeeters/tree.hh/master/doc/structure.png

Projects using tree.hh

The tree.hh library is used in various projects:

Let me know about your project when you are using tree.hh, so that I can add it to the list.

License

In principle, the tree.hh code is available under the terms of the GNU General Public License 2 or 3. However, if you would like to use tree.hh under different conditions, contact me and we will work something out.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].