This repository has been archived by the owner on Jan 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.js
107 lines (89 loc) · 2.68 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* global VisualisationItem */
/*************************************************************
* THIS IS AN EXAMPLE FILE ON ADDING A DATA STRUCTURE ITEM
************************************************************/
class ExampleDataStructure extends VisualisationItem {
constructor(itemData) {
super(
"Example Name",
itemData,
[], // State (Array of Graphic Element - each element must implement draw(env))
// State can be an abject if we override how we handle it in the draw(); (could be anything actually)
);
}
// In detail example:
async *insert(index, value) {
// Check paramas (ALL PARAMETERS ARE STRINGS BECAUSE THEY ARE USER INPUT!)
index = Number(index);
value = Number(value);
if (isNaN(index) || isNaN(value))
return {
success: false,
message: ``
};
// State changing code
// ........
// Define Step
await this.step("optional log") && (yield);
// State changing code
// ........
// Return result
return {
success: true,
message: ``
};
}
async *remove() {
// Step
await this.step() && (yield);
return {
success: true,
message: ``
};
}
async *search() {
// Step
await this.step() && (yield);
return {
success: true,
message: ``
};
}
// Multi-operation support: This method will return approiate coroutine!
async *sort() {
// Step
await this.step() && (yield);
return {
success: true,
message: ``
};
}
/*****
* Extra methods:
* - shouldYield()
* - resetState()
* - storeState()
* - clearStorage()
* - shiftState(index)
* - shiftStateToResume()
* - draw(env)
* (Override if extra functionality needed)
*/
/*****
* Event methods
* - mousePressed(env)
* - mouseReleased(env)
*/
/*****
* Constants of Parent class:
* - VisualisationItem.ASCENDING_SORTING_TYPE
* - VisualisationItem.DESCENDING_SORTING_TYPE
* - VisualisationItem.SORTING_TYPES
* - VisualisationItem.COLORS
*/
}
ExampleDataStructure.prototype.insert.help = `(Help string for 'insert')`;
ExampleDataStructure.prototype.remove.help = `(Help string for 'help')`;
ExampleDataStructure.prototype.search.help = `(Help string for 'search')`;
ExampleDataStructure.prototype.sort.help = `(Help string for 'sort')`;
module.exports = ExampleDataStructure;