Skip to content

Commit 49b91a0

Browse files
committed
overall revision of modules
1 parent e3c30f1 commit 49b91a0

File tree

9 files changed

+834
-908
lines changed

9 files changed

+834
-908
lines changed

algorithm/graph_search/bellman_ford/shortest_path/code.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ function BELLMAN_FORD (src, dest) {
33

44
for (var i = 0; i < G.length; i++) {
55
weights [i] = MAX_VALUE;
6-
tracer._weight (i, MAX_VALUE);
76
}
87
weights [src] = 0;
9-
tracer._weight (src, 0);
108

119
tracer._print ('Initializing weights to: [' + weights + ']');
1210
tracer._print ('');
@@ -55,7 +53,7 @@ function BELLMAN_FORD (src, dest) {
5553
return weights [dest];
5654
}
5755

58-
var src = Math.random() * G.length | 0, dest;
56+
var src = Math.random() * G.length | 0, dest;
5957
var MAX_VALUE = Infinity;
6058
var minWeight;
6159

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
var tracer = new DirectedGraphTracer();
2-
var G = [
3-
[0,-1,4,0,0],
4-
[0,0,3,2,2],
5-
[0,0,0,0,0],
6-
[0, 1,5,0,0],
7-
[0,0,0,-3,0]
8-
];
9-
1+
var tracer = new WeightedDirectedGraphTracer();
2+
var G = WeightedDirectedGraph.random(5, .5, -5, 5);
103
tracer._setData(G);

index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ <h3>Reference</h3>
109109
<script src="js/ace/ace.js"></script>
110110
<script src="js/module/tracer.js"></script>
111111
<script src="js/module/directed_graph.js"></script>
112-
<script src="js/module/directed_weighted_graph.js"></script>
112+
<script src="js/module/undirected_graph.js"></script>
113+
<script src="js/module/weighted_directed_graph.js"></script>
113114
<script src="js/module/array2d.js"></script>
114115
<script src="js/module/array1d.js"></script>
115116
<script src="js/script.js"></script>

js/module/array1d.js

Lines changed: 47 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,70 +2,59 @@ function Array1DTracer(module) {
22
return Array2DTracer.call(this, module || Array1DTracer);
33
}
44

5-
Array1DTracer.prototype = Object.create(Array2DTracer.prototype);
6-
Array1DTracer.prototype.constructor = Array1DTracer;
7-
8-
// Override
9-
Array1DTracer.prototype._setData = function(D) {
10-
return Array2DTracer.prototype._setData.call(this, [D]);
11-
};
12-
13-
// Override
14-
Array1DTracer.prototype._notify = function(idx1, idx2) {
15-
if (idx2 === undefined) {
16-
Array2DTracer.prototype._notify.call(this, 0, idx1);
17-
} else {
18-
Array2DTracer.prototype._notify.call(this, 0, idx1, 0, idx2);
19-
}
20-
};
21-
22-
// Override
23-
Array1DTracer.prototype._select = function(s, e) {
24-
if (e === undefined) {
25-
Array2DTracer.prototype._select.call(this, 0, s);
26-
} else {
27-
Array2DTracer.prototype._selectRow.call(this, 0, s, e);
28-
}
29-
};
30-
31-
// Override
32-
Array1DTracer.prototype._selectSet = function(indexes) {
33-
var coords = [];
34-
indexes.forEach(function(index) {
35-
coords.push({
36-
x: 0,
37-
y: index
5+
Array1DTracer.prototype = $.extend(true, Object.create(Array2DTracer.prototype), {
6+
constructor: Array1DTracer,
7+
_setData: function (D) {
8+
return Array2DTracer.prototype._setData.call(this, [D]);
9+
},
10+
_notify: function (idx1, idx2) {
11+
if (idx2 === undefined) {
12+
Array2DTracer.prototype._notify.call(this, 0, idx1);
13+
} else {
14+
Array2DTracer.prototype._notify.call(this, 0, idx1, 0, idx2);
15+
}
16+
},
17+
_select: function (s, e) {
18+
if (e === undefined) {
19+
Array2DTracer.prototype._select.call(this, 0, s);
20+
} else {
21+
Array2DTracer.prototype._selectRow.call(this, 0, s, e);
22+
}
23+
},
24+
_selectSet: function (indexes) {
25+
var coords = [];
26+
indexes.forEach(function (index) {
27+
coords.push({
28+
x: 0,
29+
y: index
30+
});
3831
});
39-
});
40-
Array2DTracer.prototype._selectSet.call(this, coords);
41-
};
42-
43-
// Override
44-
Array1DTracer.prototype._deselect = function(s, e) {
45-
if (e === undefined) {
46-
Array2DTracer.prototype._deselect.call(this, 0, s);
47-
} else {
48-
Array2DTracer.prototype._deselectRow.call(this, 0, s, e);
49-
}
50-
};
51-
52-
// Override
53-
Array1DTracer.prototype._deselectSet = function(indexes) {
54-
var coords = [];
55-
indexes.forEach(function(index) {
56-
coords.push({
57-
x: 0,
58-
y: index
32+
Array2DTracer.prototype._selectSet.call(this, coords);
33+
},
34+
_deselect: function (s, e) {
35+
if (e === undefined) {
36+
Array2DTracer.prototype._deselect.call(this, 0, s);
37+
} else {
38+
Array2DTracer.prototype._deselectRow.call(this, 0, s, e);
39+
}
40+
},
41+
_deselectSet: function (indexes) {
42+
var coords = [];
43+
indexes.forEach(function (index) {
44+
coords.push({
45+
x: 0,
46+
y: index
47+
});
5948
});
60-
});
61-
Array2DTracer.prototype._deselectSet.call(this, coords);
62-
};
49+
Array2DTracer.prototype._deselectSet.call(this, coords);
50+
}
51+
});
6352

6453
var Array1D = {
65-
random: function(N, min, max) {
54+
random: function (N, min, max) {
6655
return Array2D.random(1, N, min, max)[0];
6756
},
68-
randomSorted: function(N, min, max) {
57+
randomSorted: function (N, min, max) {
6958
return Array2D.randomSorted(1, N, min, max)[0];
7059
}
7160
};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy