-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplexity.ts
More file actions
65 lines (54 loc) · 1.67 KB
/
complexity.ts
File metadata and controls
65 lines (54 loc) · 1.67 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
import { type IMathMLEntry, mathml } from '../../../common/rich.ts'
import { intersperse } from '../../../common/support/iteration.ts'
import { type uint32 } from '../../../common/types/numbers.ts'
export class ComplexityMathMLHelper {
#getComplexityEntry(identifier: string, value: IMathMLEntry | string | uint32) {
const entry = typeof value === 'string' ?
mathml.identifier(value) :
typeof value === 'number' ? mathml.number(value) : value
return mathml.functionApplication(
mathml.identifier(identifier, 'upright'),
[entry],
)
}
logLinear(identifier: string) {
return mathml.row(
mathml.identifier(identifier),
mathml.thinmuskip(),
mathml.identifier('log'),
mathml.thinmuskip(),
mathml.identifier(identifier),
)
}
pow(identifier: string, power: uint32) {
return mathml.sup(
mathml.identifier(identifier),
mathml.number(power),
)
}
root(...entries: IMathMLEntry[]) {
return mathml.root(
'inline',
...intersperse(
entries,
mathml.operator(';', 'separator'),
),
)
}
bigOmega(value: IMathMLEntry | string | uint32) {
return this.#getComplexityEntry('Ω', value)
}
smallOmega(value: IMathMLEntry | string | uint32) {
return this.#getComplexityEntry('ω', value)
}
bigO(value: IMathMLEntry | string | uint32) {
return this.#getComplexityEntry('O', value)
}
smallO(value: IMathMLEntry | string | uint32) {
return this.#getComplexityEntry('o', value)
}
theta(value: IMathMLEntry | string | uint32) {
return this.#getComplexityEntry('Θ', value)
}
}
export const complexity = new ComplexityMathMLHelper()