1
- // import React, { useState, useContext, useEffect } from 'react';
2
- // import { GlobalContext } from '../../context/GlobalState';
3
- // import { GlobalActions } from '../../context/actions';
4
- // import ListParam from './helpers/ListParam';
5
- // import SingleValueParam from './helpers/SingleValueParam';
6
- // import '../../styles/Param.scss';
7
- // import {
8
- // singleNumberValidCheck,
9
- // genUniqueRandNumList,
10
- // successParamMsg,
11
- // errorParamMsg,
12
- // } from './helpers/ParamHelper';
13
-
14
- // // import useParam from '../../context/useParam';
15
-
16
- // const ALGORITHM_NAME = 'AVL Trees';
17
- // const INSERTION = 'Insertion';
18
- // const SEARCH = 'Search';
19
-
20
- // // DEFAULT input - enough for a tree with a few levels
21
- // // Should be the same as in REFRESH_FUNCTION
22
- // const DEFAULT_NODES = genUniqueRandNumList(12, 1, 100);
23
- // const DEFAULT_TARGET = '2';
24
-
25
- // const INSERTION_EXAMPLE = 'Please follow the example provided: 1,2,3,4. Values should also be unique.';
26
- // const SEARCH_EXAMPLE = 'Please follow the example provided: 16.';
27
- // const NO_TREE_ERROR = 'Please build a tree before running search.';
28
-
29
- // function AVLTreeParam() {
30
- // const { algorithm, dispatch } = useContext(GlobalContext);
31
- // const [message, setMessage] = useState(null);
32
- // const [nodes, setNodes] = useState(DEFAULT_NODES);
33
-
34
-
35
- // const handleInsertion = (e) => {
36
- // e.preventDefault();
37
- // const list = e.target[0].value;
38
-
39
- // if (validateListInput(list)) {
40
- // let nodes = list.split(',').map(Number);
41
- // // run search animation
42
- // dispatch(GlobalActions.RUN_ALGORITHM, {
43
- // name: 'AVLTree',
44
- // mode: 'insertion',
45
- // nodes,
46
- // });
47
- // setMessage(successParamMsg(ALGORITHM_NAME));
48
- // } else {
49
- // setMessage(errorParamMsg(ALGORITHM_NAME, INSERTION_EXAMPLE));
50
- // }
51
- // };
52
- // const handleSearch = (e) => {
53
- // e.preventDefault();
54
- // const inputValue = e.target[0].value;
55
-
56
- // if (singleNumberValidCheck(inputValue)) {
57
- // const target = parseInt(inputValue, 10);
58
-
59
- // if (
60
- // Object.prototype.hasOwnProperty.call(algorithm, 'visualisers')
61
- // && !algorithm.visualisers.tree.instance.isEmpty()
62
- // ) {
63
- // const visualiser = algorithm.chunker.visualisers;
64
- // dispatch(GlobalActions.RUN_ALGORITHM, {
65
- // name: 'AVLTree',
66
- // mode: 'search',
67
- // visualiser,
68
- // target,
69
- // });
70
- // setMessage(successParamMsg(ALGORITHM_NAME));
71
- // } else {
72
- // setMessage(errorParamMsg(ALGORITHM_NAME, NO_TREE_ERROR));
73
- // }
74
- // }
75
- // else {
76
- // setMessage(errorParamMsg(ALGORITHM_NAME, SEARCH_EXAMPLE));
77
- // }
78
- // };
79
-
80
- // return (
81
- // <>
82
- // <div className="form">
83
- // {/* Insert input */}
84
- // <ListParam
85
- // name="AVLTree"
86
- // buttonName="Insert"
87
- // mode="insertion"
88
- // formClassName="formLeft"
89
- // DEFAULT_VAL={nodes}
90
- // handleSubmit={handleInsertion}
91
- // SET_VAL={setNodes}
92
- // REFRESH_FUNCTION={(() => genUniqueRandNumList(12, 1, 100))}
93
- // ALGORITHM_NAME={INSERTION}
94
- // EXAMPLE={INSERTION_EXAMPLE}
95
- // setMessage={setMessage}
96
- // />
97
-
98
- // {/* Search input */}
99
- // {<SingleValueParam
100
- // name="AVLTree"
101
- // buttonName="Search"
102
- // mode="search"
103
- // formClassName="formRight"
104
- // handleSubmit={handleSearch}
105
- // DEFAULT_VAL={DEFAULT_TARGET}
106
- // ALGORITHM_NAME={SEARCH}
107
- // EXAMPLE={SEARCH_EXAMPLE}
108
- // setMessage={setMessage}
109
- // /> }
110
- // </div>
111
- // {/* render success/error message */}
112
- // {message}
113
- // </>
114
- // );
115
- // }
116
-
117
- // export default AVLTreeParam;
118
-
119
- // function validateListInput(input) {
120
- // const inputArr = input.split(',');
121
- // const inputSet = new Set(inputArr);
122
- // return (
123
- // inputArr.length === inputSet.size
124
- // && inputArr.every((num) => singleNumberValidCheck(num))
125
- // );
126
- // }
1
+ /**
2
+ * AVL Tree Param Component
3
+ * Including the bottom web buttons to control the animation
4
+ *
5
+ * Derived from the BSTParam.js file
6
+ */
127
7
128
8
/* eslint-disable no-prototype-builtins */
129
9
/* eslint-disable max-len */
@@ -147,8 +27,6 @@ import {
147
27
shuffleArray ,
148
28
} from './helpers/ParamHelper' ;
149
29
150
- // import useParam from '../../context/useParam';
151
-
152
30
const DEFAULT_NODES = genRandNumList ( 10 , 1 , 100 ) ;
153
31
const DEFAULT_TARGET = '2' ;
154
32
const INSERTION = 'insertion' ;
@@ -169,7 +47,6 @@ const BlueRadio = withStyles({
169
47
} ,
170
48
} ,
171
49
checked : { } ,
172
- // eslint-disable-next-line react/jsx-props-no-spreading
173
50
} ) ( ( props ) => < Radio { ...props } /> ) ;
174
51
175
52
function AVLTreeParam ( ) {
0 commit comments