Giter Club home page Giter Club logo

traversal's Introduction

traversal

Build Status Build Status Latest Version Docs License

Traversal implements generic and lazy tree traversal algorithms.

Includes:

Generic

Traversal uses generics (or type parameters) to be flexible to use, and easy to implement and fit into existing architecture.

Laziness

Laziness or lazy evaluation refers to evaluation being delayed until needed.

Traversal delays processing Nodes and fetching child Nodes until Iterator::next is called. When next is called, then traversal only processes the Nodes required for this iteration.

From Rust's docs:

Iterators (and iterator adapters) are lazy. This means that just creating an iterator doesn't do a whole lot. Nothing really happens until you call next.

โ€” Iterator - Laziness

Usage

Add this to your Cargo.toml:

[dependencies]
traversal = "0.1"

Releases

Release notes are available in the repo at CHANGELOG.md.

Algorithms

     A
    / \
   B   C
  / \ / \
 D  E F  G

Given the above tree, then the following are the orders, that each individual iterator / traversal algorithm produces.

Algorithm Order
Bft (Breadth-First Traversal) A, B, C, D, E, F, G
DftPre (Depth-First Traversal in Pre-Order) A, B, D, E, C, F, G
DftPost (Depth-First Traversal in Post-Order) D, E, B, F, G, C, A
DftPreRev (Reverse Depth-First Traversal in Pre-Order) G, F, C, E, D, B, A
DftPostRev (Reverse Depth-First Traversal in Post-Order) A, C, G, F, B, E, D

See each individual algorithm for code examples.

All Paths and Longest Paths

DftPaths and DftLongestPaths are utilities for iterating all paths and the longest paths in a tree.

Given the same tree as the previous examples, then DftPaths and DftLongestPaths produce the following paths.

DftPaths:

  • A, B
  • A, B, D
  • A, B, E
  • A, C
  • A, C, F
  • A, C, G

DftLongestPaths:

  • A, B, D
  • A, B, E
  • A, C, F
  • A, C, G

See each individual algorithm for code examples.

Cycles

  A <---+
 / \    |
B   D >-+
|   |   |
C   E >-+

DftCycles:

  • A -> D (implies D is connected with A)
  • A -> D -> E

See each individual algorithm for code examples.

traversal's People

Contributors

vallentin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.