albertorestifo / node-dijkstra

A NodeJS implementation of Dijkstra's algorithm
MIT License
158 stars 37 forks source link

support Symbol() objects as graph node name #20

Closed lyxsus closed 7 years ago

lyxsus commented 7 years ago
// example

const Graph = require ('node-dijkstra');

const g = {};

const a = {};
const b = {};

const A = Symbol ('A');
const B = Symbol ('B');
const C = Symbol ('C');

a [B] = 1;
a [C] = 10;
b [C] = 1;

g [A] = a;
g [B] = b;

const route = new Graph (g)

console.log (route.path (A, C));
codecov-io commented 7 years ago

Codecov Report

Merging #20 into master will decrease coverage by 0.68%. The diff coverage is 93.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #20      +/-   ##
==========================================
- Coverage   99.21%   98.52%   -0.69%     
==========================================
  Files           5        5              
  Lines         127      136       +9     
==========================================
+ Hits          126      134       +8     
- Misses          1        2       +1
Impacted Files Coverage Δ
libs/Graph.js 100% <100%> (ø) :arrow_up:
libs/toDeepMap.js 95.65% <87.5%> (-4.35%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 2de3f87...24e3875. Read the comment docs.

albertorestifo commented 7 years ago

Thanks for your contribution. Unfortunately, I need to decline this PR as this change is not necessary:

Starting from version v2.5.0, you can pass the constructor a Map directly. This allows you to use Symbols (or anything, really) as keys:

const Graph = require('node-dijkstra');

const A = Symbol('A');
const B = Symbol('B');
const C = Symbol('C');

const a = new Map();
a.set(B, 1);
a.set(C, 2);

const b = new Map();
b.set(A, 2);

const graph = new Map();
graph.set(A, a);
graph.set(B, b);

const route = new Graph(graph);

route.path(A, B);

See in REPL. (You can also add one node at a time. Example)