dijkstrajs
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
/****************************************************************************** | ||
@@ -62,20 +64,22 @@ * Created 2008-08-19. | ||
for (v in adjacent_nodes) { | ||
// Get the cost of the edge running from u to v. | ||
cost_of_e = adjacent_nodes[v]; | ||
if (adjacent_nodes.hasOwnProperty(v)) { | ||
// Get the cost of the edge running from u to v. | ||
cost_of_e = adjacent_nodes[v]; | ||
// Cost of s to u plus the cost of u to v across e--this is *a* | ||
// cost from s to v that may or may not be less than the current | ||
// known cost to v. | ||
cost_of_s_to_u_plus_cost_of_e = cost_of_s_to_u + cost_of_e; | ||
// Cost of s to u plus the cost of u to v across e--this is *a* | ||
// cost from s to v that may or may not be less than the current | ||
// known cost to v. | ||
cost_of_s_to_u_plus_cost_of_e = cost_of_s_to_u + cost_of_e; | ||
// If we haven't visited v yet OR if the current known cost from s to | ||
// v is greater than the new cost we just found (cost of s to u plus | ||
// cost of u to v across e), update v's cost in the cost list and | ||
// update v's predecessor in the predecessor list (it's now u). | ||
cost_of_s_to_v = costs[v]; | ||
first_visit = (typeof costs[v] === 'undefined'); | ||
if (first_visit || cost_of_s_to_v > cost_of_s_to_u_plus_cost_of_e) { | ||
costs[v] = cost_of_s_to_u_plus_cost_of_e; | ||
open.push(v, cost_of_s_to_u_plus_cost_of_e); | ||
predecessors[v] = u; | ||
// If we haven't visited v yet OR if the current known cost from s to | ||
// v is greater than the new cost we just found (cost of s to u plus | ||
// cost of u to v across e), update v's cost in the cost list and | ||
// update v's predecessor in the predecessor list (it's now u). | ||
cost_of_s_to_v = costs[v]; | ||
first_visit = (typeof costs[v] === 'undefined'); | ||
if (first_visit || cost_of_s_to_v > cost_of_s_to_u_plus_cost_of_e) { | ||
costs[v] = cost_of_s_to_u_plus_cost_of_e; | ||
open.push(v, cost_of_s_to_u_plus_cost_of_e); | ||
predecessors[v] = u; | ||
} | ||
} | ||
@@ -119,6 +123,8 @@ } | ||
t = {}, | ||
opts = opts || {}, | ||
key; | ||
opts = opts || {}; | ||
for (key in T) { | ||
t[key] = T[key]; | ||
if (T.hasOwnProperty(key)) { | ||
t[key] = T[key]; | ||
} | ||
} | ||
@@ -125,0 +131,0 @@ t.queue = []; |
{ | ||
"name": "dijkstrajs", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A simple JavaScript implementation of Dijkstra's single-source shortest-paths algorithm.", | ||
"main": "dijkstra.js", | ||
"scripts": { | ||
"test": "node tests.js" | ||
"pretest": "jshint dijkstra.js", | ||
"test": "mocha -R spec" | ||
}, | ||
@@ -24,3 +25,37 @@ "repository": { | ||
}, | ||
"homepage": "https://github.com/tcort/dijkstrajs" | ||
"homepage": "https://github.com/tcort/dijkstrajs", | ||
"devDependencies": { | ||
"expect.js": "^0.3.1", | ||
"jshint": "^2.8.0", | ||
"mocha": "^2.3.3" | ||
}, | ||
"jshintConfig": { | ||
"bitwise": true, | ||
"curly": true, | ||
"eqeqeq": true, | ||
"forin": true, | ||
"freeze": true, | ||
"globalstrict": true, | ||
"immed": true, | ||
"indent": 4, | ||
"moz": true, | ||
"newcap": true, | ||
"noarg": true, | ||
"node": true, | ||
"noempty": true, | ||
"nonew": true, | ||
"trailing": true, | ||
"undef": true, | ||
"smarttabs": true, | ||
"strict": true, | ||
"validthis": true, | ||
"globals": { | ||
"describe": false, | ||
"it": false, | ||
"before": false, | ||
"beforeEach": false, | ||
"after": false, | ||
"afterEach": false | ||
} | ||
} | ||
} |
@@ -21,11 +21,3 @@ # dijkstrajs.js | ||
See `tests.js` in the sources for some example code. | ||
See `test/dijkstra.test.js` in the sources for some example code. | ||
## Contributing | ||
1. Fork it | ||
2. Create your feature branch (`git checkout -b my-new-feature`) | ||
3. Commit your changes (`git commit -am 'Add some feature'`) | ||
4. Push to the branch (`git push origin my-new-feature`) | ||
5. Create new Pull Request | ||
Sorry, the diff of this file is not supported yet
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license
Found 1 instance in 1 package
11010
8
230
3
2
80
23