Skip to content

Commit feb63e3

Browse files
committed
1 parent 2a28496 commit feb63e3

File tree

4 files changed

+40
-40
lines changed

4 files changed

+40
-40
lines changed

src/data-structures/edge.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
(function (exports) {
2+
'use strict';
3+
4+
/**
5+
* Graph edge.
6+
*
7+
* @constructor
8+
* @public
9+
* @param {Vertex} e Vertex which this edge connects.
10+
* @param {Vertex} v Vertex which this edge connects.
11+
* @param {Number} distance Weight of the edge.
12+
* @module data-structures/edge
13+
*/
14+
exports.Edge = function (e, v, distance) {
15+
this.e = e;
16+
this.v = v;
17+
this.distance = distance;
18+
};
19+
20+
})(typeof window === 'undefined' ? module.exports : window);

src/data-structures/vertex.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
(function (exports) {
2+
'use strict';
3+
4+
/**
5+
* Graph vertex.
6+
*
7+
* @constructor
8+
* @public
9+
* @param {Number} id Id of the vertex.
10+
* @module data-structures/vertex
11+
*/
12+
exports.Vertex = function (id) {
13+
this.id = id;
14+
};
15+
16+
})(typeof window === 'undefined' ? module.exports : window);

src/graphs/shortest-path/bellman-ford.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,8 @@
3535

3636
'use strict';
3737

38-
/**
39-
* Graph edge.
40-
*
41-
* @constructor
42-
* @public
43-
* @param {Vertex} u Start vertex.
44-
* @param {Vertex} v End vertex.
45-
* @param {Number} weight Weight of the edge.
46-
*/
47-
exports.Edge = function (u, v, weight) {
48-
this.from = u;
49-
this.to = v;
50-
this.weight = weight;
51-
};
38+
exports.Vertex = require('../../data-structures/vertex').Vertex;
39+
exports.Edge = require('../../data-structures/edge').Edge;
5240

5341
/**
5442
* Computes shortest paths from a single source

src/graphs/spanning-trees/prim.js

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,32 +45,8 @@
4545
'use strict';
4646

4747
var Heap = require('../../data-structures/heap').Heap;
48-
49-
/**
50-
* Graph vertex.
51-
*
52-
* @constructor
53-
* @public
54-
* @param {Number} id Id of the vertex.
55-
*/
56-
exports.Vertex = function (id) {
57-
this.id = id;
58-
};
59-
60-
/**
61-
* Graph edge.
62-
*
63-
* @constructor
64-
* @public
65-
* @param {Vertex} e Vertex which this edge connects.
66-
* @param {Vertex} v Vertex which this edge connects.
67-
* @param {Number} distance Weight of the edge.
68-
*/
69-
exports.Edge = function (e, v, distance) {
70-
this.e = e;
71-
this.v = v;
72-
this.distance = distance;
73-
};
48+
exports.Vertex = require('../../data-structures/vertex').Vertex;
49+
exports.Edge = require('../../data-structures/edge').Edge;
7450

7551
/**
7652
* Graph.

0 commit comments

Comments
 (0)