Socket
Socket
Sign inDemoInstall

bellmanford

Package Overview
Dependencies
1
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    bellmanford

bellmanford ===========


Version published
Maintainers
1
Install size
103 kB
Created

Readme

Source

bellmanford

An implementation of the Bellman-Ford algorithm in TypeScript. It is not dependent on node.js, but it does use CommonJS style exports.

To install, use:

npm install bellmanford

It can be used from both TypeScript and JavaScript. The NodeList expects elements that implement the interface INode. INode has only one property: id of type number. As long as your nodes each have distinct ids, you should be fine.

TypeScript:

import bf = module("bellmanford");

var nodeList = new bf.NodeList();
    
for (var i = 0; i < 6; i++) {
nodeList.addNode(new bf.Node());
}

var nodeArray = nodeList.toArray();

var edgeMap = new bf.EdgeMap(nodeList);

edgeMap.setEdge(nodeArray[0], nodeArray[1], 3);
edgeMap.setEdge(nodeArray[0], nodeArray[2], 2);
edgeMap.setEdge(nodeArray[0], nodeArray[3], 5);

edgeMap.setEdge(nodeArray[1], nodeArray[3], 1);
edgeMap.setEdge(nodeArray[1], nodeArray[4], 4);

edgeMap.setEdge(nodeArray[2], nodeArray[3], 2);
edgeMap.setEdge(nodeArray[2], nodeArray[5], 1);

edgeMap.setEdge(nodeArray[3], nodeArray[4], 3);

edgeMap.setEdge(nodeArray[4], nodeArray[5], 2);

var graph = new bf.Graph(nodeList, edgeMap);

var shortestPaths = graph.getShortestPathsSync(nodeArray[0]);

Keywords

FAQs

Last updated on 24 Mar 2013

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc