diff --git a/src/algorithms/index.js b/src/algorithms/index.js index 7115b9e08..92abfa734 100644 --- a/src/algorithms/index.js +++ b/src/algorithms/index.js @@ -153,8 +153,8 @@ const allalgs = { }, }, - 'Hashing': { - name: 'Hashing', + 'Hashing (LP)': { + name: 'Hashing (linear probing)', category: 'Insert/Search', param: , instructions: Instructions.HashingInstruction, @@ -170,6 +170,23 @@ const allalgs = { }, }, + 'Hashing (DH)': { + name: 'Hashing (double hashing)', + category: 'Insert/Search', + param: , + instructions: Instructions.HashingInstruction, + explanation: Explanation.HashingExp, + extraInfo: ExtraInfo.HashingInfo, + pseudocode: { + insertion: Pseudocode.HashingInsert, + search: Pseudocode.HashingSearch, + }, + controller: { + insertion: Controller.HashingInsert, + search: Controller.HashingSearch, + }, + }, + 'DFSrec': { name: 'Depth First Search', category: 'Graph', diff --git a/src/algorithms/parameters/HashingParam.js b/src/algorithms/parameters/HashingParam.js index e76f16cbe..46a69d142 100644 --- a/src/algorithms/parameters/HashingParam.js +++ b/src/algorithms/parameters/HashingParam.js @@ -1,113 +1,117 @@ import React, { useState, useContext, useEffect } from 'react'; import { GlobalContext } from '../../context/GlobalState'; import { GlobalActions } from '../../context/actions'; +import FormControlLabel from '@mui/material/FormControlLabel'; +import Radio from '@mui/material/Radio'; +import { withStyles } from '@mui/styles'; import ListParam from './helpers/ListParam'; import SingleValueParam from './helpers/SingleValueParam'; import '../../styles/Param.scss'; -import { - singleNumberValidCheck, - genUniqueRandNumList, - successParamMsg, - errorParamMsg, -} from './helpers/ParamHelper'; +import {genUniqueRandNumList} from './helpers/ParamHelper'; // import useParam from '../../context/useParam'; const ALGORITHM_NAME = 'Hashing'; -const INSERTION = 'Insertion'; -const SEARCH = 'Search'; - -// DEFAULT input - enough for a tree with a few levels -// Should be the same as in REFRESH_FUNCTION -const DEFAULT_NODES = genUniqueRandNumList(12, 1, 100); -const DEFAULT_TARGET = '2'; - -const INSERTION_EXAMPLE = 'Please follow the example provided: 1,2,3,4. Values should also be unique.'; -const SEARCH_EXAMPLE = 'Please follow the example provided: 16.'; -const NO_TREE_ERROR = 'Please build a tree before running search.'; - -function TTFTreeParam() { - // const { algorithm, dispatch } = useContext(GlobalContext); - // const [message, setMessage] = useState(null); - // const [nodes, setNodes] = useState(DEFAULT_NODES); - // - // - // const handleInsertion = (e) => { - // e.preventDefault(); - // const list = e.target[0].value; - // - // if (validateListInput(list)) { - // let nodes = list.split(',').map(Number); - // // run search animation - // dispatch(GlobalActions.RUN_ALGORITHM, { - // name: 'TTFTree', - // mode: 'insertion', - // nodes, - // }); - // setMessage(successParamMsg(ALGORITHM_NAME)); - // } else { - // setMessage(errorParamMsg(ALGORITHM_NAME, INSERTION_EXAMPLE)); - // } - // }; - // const handleSearch = (e) => { - // e.preventDefault(); - // const inputValue = e.target[0].value; - // - // if (singleNumberValidCheck(inputValue)) { - // const target = parseInt(inputValue, 10); - // - // if ( - // Object.prototype.hasOwnProperty.call(algorithm, 'visualisers') - // && !algorithm.visualisers.tree.instance.isEmpty() - // ) { - // const visualiser = algorithm.chunker.visualisers; - // dispatch(GlobalActions.RUN_ALGORITHM, { - // name: 'TTFTree', - // mode: 'search', - // visualiser, - // target, - // }); - // setMessage(successParamMsg(ALGORITHM_NAME)); - // } else { - // setMessage(errorParamMsg(ALGORITHM_NAME, NO_TREE_ERROR)); - // } - // } - // else { - // setMessage(errorParamMsg(ALGORITHM_NAME, SEARCH_EXAMPLE)); - // } - // }; +const HASHING_INSERT = 'Hashing Insertion'; +const HASHING_SEARCH = 'Hashing Search'; +const HASHING_EXAMPLE = 'PLACE HOLDER ERROR MESSAGE'; + +const DEFAULT_ARRAY = genUniqueRandNumList(10, 1, 50); +const DEFAULT_SEARCH = '...' +const UNCHECKED = { + smallTable: false, + largeTable: false +}; + +const BlueRadio = withStyles({ + root: { + color: '#2289ff', + '&$checked': { + color: '#027aff', + }, + }, + checked: {}, + // eslint-disable-next-line react/jsx-props-no-spreading +})((props) => ) + + +//const ERROR_INPUT = 'Please enter only positive integers'; +//const ERROR_TOO_LARGE = `Please enter only ${HASHING_FUNCTION} digits in the table`; + + +function HashingParam() { + const [message, setMessage] = useState(null); + const [array, setArray] = useState(DEFAULT_ARRAY); + const [search, setSearch] = useState(DEFAULT_SEARCH); + const [size, setSize] = useState({ + smallTable: true, + largeTable: false, + }); + + const handleChange = (e) => { + setSize({ ...UNCHECKED, [e.target.name]: true }) + } + + useEffect( + () => { + document.getElementById('startBtnGrp').click(); + }, + [size], + ); + return ( <>
- {/* Insert input */} - {/* Search input */} + {} + DEFAULT_VAL = {DEFAULT_SEARCH} + SET_VAL = {setSearch} + ALGORITHM_NAME = {HASHING_SEARCH} + setMessage={setMessage} + />}
- {/* render success/error message */} + + + } + label="Small Table" + className="checkbox" + /> + + } + label="Large Table" + className="checkbox" + /> ); } -export default TTFTreeParam; - -function validateListInput(input) { - const inputArr = input.split(','); - const inputSet = new Set(inputArr); - return ( - inputArr.length === inputSet.size - && inputArr.every((num) => singleNumberValidCheck(num)) - ); -} +export default HashingParam;