Code Monkey home page Code Monkey logo

graph's Introduction

graph

Simple graph with a parallel node walker

Usage

A graph is constructed using a series of linkers, each linker containing a single node. Each linker by default has one input and one output connector, which might be used to connect to other linkers:

linker1.Link(linker1)

or

linker1.Connect(linker2, linker1.Connector(graph.InputName), linker2.Connector(graph.OutputName, graph.OutputType))

Once a chain has been finalized, a starting linker can be selected to act as the first root to be used when walking over the graph. This root can be used to create a walker, which upon creation will find any other roots in the graph, and calculate the total number of nodes in it. Walking the graph will produce a channel, which will emit a new item for each node. Any processing of these items can be done concurrently, since nodes will wait for their dependencies to finish processing. The user has to notify the walker by closing the item once processing has finished. Once all nodes have been walked, the channel will be closed.

w := graph.NewWalker(root)

for wd := range w.Walk() {
    go func(wd graph.WalkData) {
      defer wd.Close()
      
      // Do whatever operation can be identified by the current node
    }(wd)
}

A complete example can be read here

graph's People

Contributors

urandom avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.