Skip to content

Commit 2472c19

Browse files
Bugfixes og fjernet død kode
1 parent d1c24f9 commit 2472c19

17 files changed

+90
-320
lines changed

UnionFind/js/Controller.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,16 @@ var Controller = /** @class */ (function () {
2626
};
2727
Controller.prototype.connected = function (firstIndex, secondIndex) {
2828
viewer.screenLockThis(true);
29-
//Kossen gjør eg detta?? - fixed tror jeg
3029
this.algorithm.connected(firstIndex, secondIndex);
3130
viewer.screenLockThis(false);
3231
};
3332
Controller.prototype.union = function (firstIndex, secondIndex) {
3433
viewer.screenLockThis(true);
35-
//samme som over - fixed tror jeg
3634
this.algorithm.union(firstIndex, secondIndex);
3735
viewer.screenLockThis(false);
3836
};
3937
Controller.prototype.find = function (index) {
4038
viewer.screenLockThis(true);
41-
//SEND HELP PLEASE
4239
this.algorithm.find(index);
4340
viewer.screenLockThis(false);
4441
};
@@ -57,9 +54,6 @@ var Controller = /** @class */ (function () {
5754
Controller.prototype.highlightNode = function (index, color) {
5855
viewer.highlightThisNode(index, color);
5956
};
60-
Controller.prototype.invertPauseState = function () {
61-
this.algorithm.invertPause();
62-
};
6357
Controller.prototype.setAlgorithm = function (algo) {
6458
this.algorithm = algo;
6559
};

UnionFind/js/Controller.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ let jColor = 0;
1111

1212
class Controller {
1313

14-
//algorithm og methodToUse skal ikke være string, men dei e det for nå
15-
//programmet vil ikje fungere
1614
private algorithm: IAlgorithm;
1715
private methodToUse: string = "Union";
1816
private speed: number;
19-
private GUI: IView; // Mulig forskjellig View for ulike algoritmer?
17+
private GUI: IView;
2018

2119
initController(algo: IAlgorithm) {
2220
manager.start();
@@ -36,21 +34,18 @@ class Controller {
3634

3735
connected(firstIndex: number, secondIndex: number) {
3836
viewer.screenLockThis(true);
39-
//Kossen gjør eg detta?? - fixed tror jeg
4037
this.algorithm.connected(firstIndex, secondIndex);
4138
viewer.screenLockThis(false);
4239
}
4340

4441
union(firstIndex: number, secondIndex: number) {
4542
viewer.screenLockThis(true);
46-
//samme som over - fixed tror jeg
4743
this.algorithm.union(firstIndex, secondIndex);
4844
viewer.screenLockThis(false);
4945
}
5046

5147
find(index: number) {
5248
viewer.screenLockThis(true);
53-
//SEND HELP PLEASE
5449
this.algorithm.find(index);
5550
viewer.screenLockThis(false);
5651
}
@@ -75,10 +70,6 @@ class Controller {
7570
viewer.highlightThisNode(index, color);
7671
}
7772

78-
invertPauseState() {
79-
this.algorithm.invertPause();
80-
}
81-
8273
setAlgorithm(algo: IAlgorithm) {
8374
this.algorithm = algo;
8475
}

UnionFind/js/EventManager.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ var EventManager = /** @class */ (function () {
4343
EventManager.prototype.pause = function () {
4444
clearInterval(this.eventThread);
4545
};
46+
EventManager.prototype.clear = function () {
47+
this.pause();
48+
this.nextEvents = [];
49+
this.previousEvents = [];
50+
this.start();
51+
};
4652
return EventManager;
4753
}());
4854
var FrontendEvent = /** @class */ (function () {
@@ -54,15 +60,3 @@ var FrontendEvent = /** @class */ (function () {
5460
return FrontendEvent;
5561
}());
5662
var manager = new EventManager();
57-
/*
58-
/** How to add FrontendEvents to manager
59-
for(var i=0; i<10; i++) {
60-
var f = function(k) {
61-
return function() {console.log("Going forward, step " + k);};
62-
}(i);
63-
var b = function(k) {
64-
return function() {console.log("Going backward, step " + k);}
65-
}(i);
66-
manager.addEvent(new FrontendEvent(f,b));
67-
}
68-
*/

UnionFind/js/EventManager.ts

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
*
44
*/
55

6-
declare var $ : any;
6+
declare var $: any;
77

88
/** Manager for events stored in queue. Manager is also responsible for executing events automatically */
99
class EventManager {
10-
delayTime:number = 400; // Original value
11-
nextEvents:FrontendEvent[] = [];
12-
previousEvents:FrontendEvent[] = [];
13-
eventThread : number;
10+
delayTime: number = 400; // Original value
11+
nextEvents: FrontendEvent[] = [];
12+
previousEvents: FrontendEvent[] = [];
13+
eventThread: number;
1414

1515
// Executing the next event in the queue, adding it to 'previous'
1616
next() {
@@ -29,51 +29,45 @@ class EventManager {
2929
previous() {
3030
if (this.previousEvents.length == 0)
3131
return;
32-
var event :FrontendEvent = (<FrontendEvent>this.previousEvents.pop());
32+
var event: FrontendEvent = (<FrontendEvent>this.previousEvents.pop());
3333
//this.delayTime = 0; //TODO: Should there be a delay when stepping backwards?
3434
event.previous();
3535
this.nextEvents.unshift(event);
3636
}
3737

38-
addEvent(event : FrontendEvent) {
38+
addEvent(event: FrontendEvent) {
3939
this.nextEvents.push(event);
4040
}
4141

4242
start() {
4343
clearInterval(this.eventThread);
4444
var manager = this; // Anonymous functions cannot access this...
45-
this.eventThread = setInterval(function() {
45+
this.eventThread = setInterval(function () {
4646
manager.next();
47-
}, manager.delayTime);
47+
}, manager.delayTime);
4848
}
4949

5050
pause() {
5151
clearInterval(this.eventThread);
5252
}
53+
54+
clear(): void {
55+
this.pause();
56+
this.nextEvents = [];
57+
this.previousEvents = [];
58+
this.start();
59+
}
5360
}
5461

5562
class FrontendEvent {
56-
next : Function;
57-
previous : Function;
58-
duration:number;
59-
constructor(n : Function, p : Function, d:number) {
63+
next: Function;
64+
previous: Function;
65+
duration: number;
66+
constructor(n: Function, p: Function, d: number) {
6067
this.next = n;
6168
this.previous = p;
6269
this.duration = d;
6370
}
6471
}
6572

66-
var manager:EventManager = new EventManager();
67-
68-
/*
69-
/** How to add FrontendEvents to manager
70-
for(var i=0; i<10; i++) {
71-
var f = function(k) {
72-
return function() {console.log("Going forward, step " + k);};
73-
}(i);
74-
var b = function(k) {
75-
return function() {console.log("Going backward, step " + k);}
76-
}(i);
77-
manager.addEvent(new FrontendEvent(f,b));
78-
}
79-
*/
73+
var manager: EventManager = new EventManager();

UnionFind/js/IAlgorithm.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,6 @@ interface IAlgorithm {
2626
*/
2727
getArray(): number[];
2828

29-
/**
30-
* Called when the pause-button (SPACE) is hit
31-
* Sets the pause variable to !pause
32-
*/
33-
invertPause(): void;
34-
35-
/**
36-
* Set the Controller for this algorithm
37-
* @param Controller
38-
*/
39-
setController(control: Controller): void;
40-
4129
/**
4230
* Set the current state of the algorithm to the given array
4331
* @param array

UnionFind/js/QuickFind.js

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* File created by Philip Hoang 06.2.
3-
* written by Øyvind ;););)
3+
* written by Øyvind
44
* based on QuickFind.Java
55
*/
66
///<reference path="Controller.ts"/>
@@ -13,29 +13,22 @@ var QuickFind = /** @class */ (function () {
1313
for (var i = 0; i < size; i++) {
1414
this.arr[i] = i;
1515
}
16-
this.pause = false;
1716
}
1817
QuickFind.prototype.union = function (aIndex, bIndex) {
1918
var aRoot = this.arr[aIndex];
2019
var bRoot = this.arr[bIndex];
2120
if (aRoot == bRoot) {
22-
this.delay(this.getDelayTime() * 2);
2321
control.setSelectedIndex(aIndex, false);
2422
control.setSelectedIndex(bIndex, false);
2523
return;
2624
}
2725
control.saveState(this.arr);
2826
for (var i = 0; i < this.arr.length; i++) {
29-
while (this.pause) {
30-
this.delay(this.getDelayTime());
31-
}
3227
control.setArrow(i);
33-
this.delay(this.getDelayTime());
3428
if (this.arr[i] == aRoot) {
3529
control.setValueAtIndex(i, bRoot);
3630
control.connectNodes(i, bRoot);
3731
this.arr[i] = bRoot;
38-
this.delay(this.getDelayTime());
3932
}
4033
}
4134
control.setArrow(-1);
@@ -51,30 +44,19 @@ var QuickFind = /** @class */ (function () {
5144
}
5245
else
5346
control.redCross(aIndex, bIndex, true);
54-
this.delay(this.getDelayTime());
55-
this.removeHighlighFromRoot(aIndex);
56-
this.removeHighlighFromRoot(bIndex);
47+
control.setSelectedIndex(bIndex, false);
48+
control.removeHighlight(this.arr[bIndex]);
49+
control.setSelectedIndex(aIndex, false);
50+
control.removeHighlight(this.arr[aIndex]);
5751
control.checkMark(aIndex, bIndex, false);
5852
control.redCross(aIndex, bIndex, false);
5953
return connected;
6054
};
6155
QuickFind.prototype.getName = function () {
6256
return this.name;
6357
};
64-
QuickFind.prototype.removeHighlighFromRoot = function (pIndex) {
65-
control.removeHighlight(this.arr[pIndex]);
66-
};
67-
QuickFind.prototype.delay = function (delayTime) {
68-
/*
69-
let start = new Date().getTime();
70-
for (let i = 0; i < 1e7; i++) {
71-
if ((new Date().getTime() - start) > delayTime)
72-
break;
73-
}*/
74-
};
7558
QuickFind.prototype.find = function (pIndex) {
7659
var root = this.simpleFind(pIndex, "green");
77-
this.delay(this.getDelayTime());
7860
control.removeHighlight(root);
7961
control.setSelectedIndex(pIndex, false);
8062
return root;
@@ -83,7 +65,6 @@ var QuickFind = /** @class */ (function () {
8365
var root = this.arr[pIndex];
8466
if (pIndex != root) {
8567
control.highlightNode(pIndex, "orange");
86-
this.delay(this.getDelayTime());
8768
control.removeHighlight(pIndex);
8869
}
8970
control.highlightNode(root, color);
@@ -95,20 +76,11 @@ var QuickFind = /** @class */ (function () {
9576
QuickFind.prototype.setArray = function (array) {
9677
this.arr = array;
9778
};
98-
QuickFind.prototype.isPause = function () {
99-
return this.pause;
100-
};
101-
QuickFind.prototype.invertPause = function () {
102-
this.pause = !this.pause;
103-
};
10479
QuickFind.prototype.connectedNoGUIUpdate = function (a, b) {
10580
return this.arr[a] == this.arr[b];
10681
};
10782
QuickFind.prototype.getDelayTime = function () {
10883
return this.DELAY + control.getSpeed();
10984
};
110-
QuickFind.prototype.setController = function (control) {
111-
//
112-
};
11385
return QuickFind;
11486
}());

0 commit comments

Comments
 (0)