Skip to content

Commit

Permalink
rename api
Browse files Browse the repository at this point in the history
  • Loading branch information
j50n committed Dec 27, 2021
1 parent 8142763 commit 354cd5c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

A pretty good implementation of Dijkstra's shortest-path algorithm for Deno.

This implementation is able to process large in-memory graphs. It will
perform reasonably well even when the number of edges is in the millions.
This implementation is able to process large in-memory graphs. It will perform
reasonably well even when the number of edges is in the millions.

This code was adapted from Typescript/Deno from
[A Walkthrough of Dijkstra's Algorithm (In JavaScript!)](https://medium.com/@adriennetjohnson/a-walkthrough-of-dijkstras-algorithm-in-javascript-e94b74192026)
Expand Down Expand Up @@ -46,7 +46,7 @@ assertEquals(
);

assertEquals(
cafes.calculateFor(FULLSTACK).weights[CAFEGRUMPY],
cafes.calculateFor(FULLSTACK).weightOfPathTo(CAFEGRUMPY),
14,
);
```
2 changes: 1 addition & 1 deletion dijkstra.example.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Deno.test("demonstrate finding shortest path", () => {

Deno.test("demonstrate finding the weight of the shortest path", () => {
assertEquals(
cafes.calculateFor(FULLSTACK).totalWeight(CAFEGRUMPY),
cafes.calculateFor(FULLSTACK).weightOfPathTo(CAFEGRUMPY),
14,
"weight of the shortest path",
);
Expand Down
4 changes: 2 additions & 2 deletions dijkstra.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Deno.test("some paths are valid, others are not", () => {
const shortestPath = solver.calculateFor(0);
assertThrows(() => shortestPath.shortestPathTo(1), Error);
assertEquals(shortestPath.shortestPathTo(2), [0, 2]);
assertEquals(shortestPath.totalWeight(2), 42);
assertEquals(shortestPath.weightOfPathTo(2), 42);
});

Deno.test("finds shortest path between two nodes", () => {
Expand All @@ -27,5 +27,5 @@ Deno.test("finds shortest path between two nodes", () => {

const shortestPath = solver.calculateFor(0);
assertEquals(shortestPath.shortestPathTo(1), [0, 1]);
assertEquals(shortestPath.totalWeight(1), 1);
assertEquals(shortestPath.weightOfPathTo(1), 1);
});
2 changes: 1 addition & 1 deletion dijkstra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export class ShortestPaths {
* Total weight of the path from the start node to the given end node.
* @param endNode The end node.
*/
totalWeight(endNode: number): number {
weightOfPathTo(endNode: number): number {
if (endNode < 0 || endNode >= this.nodes) {
throw new RangeError(
`end-node must be in range 0 to ${this.nodes - 1}: ${endNode}`,
Expand Down

0 comments on commit 354cd5c

Please sign in to comment.