Skip to content

lcucurachi/go-tree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚀 Go-Tree - A simple tree library with visualisation capabilities

GoDoc Go Report Card Go Version Release License

A tree is defined as a graph having three properties:

  • a single root node with no parent
  • all non-root nodes have exactly one parent
  • any node may have any number of children

The nodes of the tree are assumed to have an id or key by which parent and child relationships can be defined.

Only a node entity has been coded which can represent both root and non root nodes. How the root node is identified is up to you.

❓ Why

The idea to build this library came from the necessity to graphically visualise data that can be represented in a tree structure and analyse it visually.

Example:

  • You have an API that returns a JSON with a tree like structure and you want to easily visualise and map this data to understand what the structure looks like.
  • You are parsing data that is in a random order (parents are not sorted) and you want to build a tree of the data so the structure of the data can be visualised on screen.

⚡ Installation

  • With go get:
go get -u github.com/lcucurachi/go-tree

🛠️ Basic Example

Call NewNode() constructor with the datatype that you want to store in the nodes and create a root node that has a distinct id and title (root and root is okay).

Case 1: Unsorted Data

If your data is unsorted you cannot link nodes immediately as the parent node might not exist yet. Look at examples/generic for an example of how to correctly build a tree of unsorted data.

Case 2: Sorted Data

Similar to the unsorted case, build your nodes with NewNode() and then use AddChildren() and MoveNodeParent() to build the tree.

Or create nodes and assign children directly using NewNodeWithChildren().

💡 TODO

  • Implement a more efficient tree search so that the library can be used to build and search bigger trees more efficiently.
  • More tests.

Contributions

We welcome all contributions, whether it's bug reports, feature requests, or pull requests.

About

A simple tree library with visualisation capabilities

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages