-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.py
More file actions
54 lines (48 loc) · 1.01 KB
/
functions.py
File metadata and controls
54 lines (48 loc) · 1.01 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
from enum import StrEnum
import numpy as np
PHI = (1 + 5 ** 0.5) / 2
class FunctionName(StrEnum):
CONSTANT = 'O(1) (constant)'
LOGARITHMIC = 'O(log n) (logarithmic)'
LINEAR = 'O(n) (linear)'
LOGLINEAR = 'O(n log n) (loglinear)'
QUADRATIC = 'O(n^2) (quadratic)'
CUBIC = 'O(n^3) (cubic)'
EXPONENTIAL_PHI = 'O(phi^n) (exponential)'
EXPONENTIAL_2 = 'O(2^n) (exponential)'
# Note: Functions must be ordered from
# slowest-growing to fastest-growing
common_functions = [
{
'name': FunctionName.CONSTANT,
'fn': lambda x: x * 0,
},
{
'name': FunctionName.LOGARITHMIC,
'fn': lambda x: np.log2(x),
},
{
'name': FunctionName.LINEAR,
'fn': lambda x: x,
},
{
'name': FunctionName.LOGLINEAR,
'fn': lambda x: x * np.log2(x),
},
{
'name': FunctionName.QUADRATIC,
'fn': lambda x: x * x,
},
{
'name': FunctionName.CUBIC,
'fn': lambda x: x * x * x,
},
{
'name': FunctionName.EXPONENTIAL_PHI,
'fn': lambda x: PHI ** x,
},
{
'name': FunctionName.EXPONENTIAL_2,
'fn': lambda x: 2 ** x,
},
]