-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathitems.js
More file actions
88 lines (74 loc) · 1.61 KB
/
Copy pathitems.js
File metadata and controls
88 lines (74 loc) · 1.61 KB
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
export const O = {
CONSTANT: "1",
LINEAR: "n",
LOGARITHMIC: "log(n)",
QUADRATIC: "n^2",
LINEARITHMIC: "n log(n)"
}
export const Type = {
COLLECTION: 0,
SORT: 1
}
export class Collection {
constructor(insert, remove=insert, access=insert, search=insert) {
this.insert = insert;
this.remove = remove;
this.access = access;
this.search = search;
}
getInsert() {
return this.insert;
}
getRemove() {
return this.remove;
}
getAccess() {
return this.access;
}
getSearch() {
return this.search;
}
getLabels() {
return ["Insert", "Remove", "Access", "Search"];
}
}
export class SortAlgorithm {
constructor(best, worst=best, average=best) {
this.best = best;
this.worst = worst;
this.average = average;
}
getBest() {
return this.best;
}
getWorst() {
return this.worst;
}
getAverage() {
return this.average;
}
getLabels() {
return ["Best", "Worst", "Average"];
}
}
export class Item {
constructor(name, type, complexity) {
this.name = name;
this.type = type;
// complexity is either a Collection or SearchAlgorithm
this.complexity = complexity;
}
/**
*
* @param {string[]} labels
* @returns {string[]} values
*/
makeTableRow(labels) {
const items = [this.name];
labels.forEach(label => {
const value = this.complexity["get"+label]();
items.push(value);
});
return items;
}
}