New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@algorithm.ts/graph

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@algorithm.ts/graph

Types and utils from solving graph problems.

  • 2.0.14
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@algorithm.ts/graph


Types and utils from solving graph problems.

Install

  • npm

    npm install --save @algorithm.ts/graph
    
  • yarn

    yarn add @algorithm.ts/graph
    
  • deno

    import type { IEdge, IGraph } from 'https://raw.githubusercontent.com/guanghechen/algorithm.ts/main/packages/graph/src/index.ts'
    import { buildEdgeMap } from 'https://raw.githubusercontent.com/guanghechen/algorithm.ts/main/packages/graph/src/index.ts'
    

Usage

  • buildEdgeMap

    import { buildEdgeMap } from '@algorithm.ts/graph'
    
    const Nodes = {
      A: 0,
      B: 1,
      C: 2,
      D: 3,
    }
    const N: number = Object.keys(Nodes).length
    const edges: Array<IEdge & { from: number }> = [
      { from: Nodes.A, to: Nodes.B, cost: 1 }, // A-B (1)
      { from: Nodes.B, to: Nodes.A, cost: -1 }, // B-A (-1)
      { from: Nodes.B, to: Nodes.C, cost: 0.87 }, // B-C (0.87)
      { from: Nodes.C, to: Nodes.B, cost: -0.87 }, // C-B (-0.87)
      { from: Nodes.C, to: Nodes.D, cost: 5 }, // C-D (5)
      { from: Nodes.D, to: Nodes.C, cost: -5 }, // D-C (-5)
    ]
    
    const G: number[][] = buildEdgeMap(N, edges)
    
    const graph: IGraph = { N, edges, G }
    
  • getShortestPath

    import { getShortestPath } from '@algorithm.ts/graph'
    
    /**
     * @param bestFrom  Record the shortest path parent source point to the specified point.
     * @param source    The source node on the shortest path.
     * @param target    The target node on the shortest path.
     */
    getShortestPath(bestFrom: number[], source: number, target: number): number[] // nodes 
    

Keywords

FAQs

Package last updated on 27 Aug 2022

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc