diff --git a/src/algorithms/controllers/HashingCommon.js b/src/algorithms/controllers/HashingCommon.js
new file mode 100644
index 000000000..dfce11529
--- /dev/null
+++ b/src/algorithms/controllers/HashingCommon.js
@@ -0,0 +1,2 @@
+import Array2DTracer from '../../components/DataStructures/Array/Array2DTracer';
+
diff --git a/src/algorithms/controllers/HashingDH.js b/src/algorithms/controllers/HashingDH.js
new file mode 100644
index 000000000..6f37db3f1
--- /dev/null
+++ b/src/algorithms/controllers/HashingDH.js
@@ -0,0 +1,25 @@
+import Array2DTracer from '../../components/DataStructures/Array/Array2DTracer';
+
+export default {
+ initVisualisers() {
+ return {
+ array: {
+ instance: new Array2DTracer('array', null, 'Hash Table'),
+ order: 0,
+ },
+ };
+ },
+
+ run(chunker) {
+ chunker.add(
+ 'HashSearch(T, k)',
+ (vis, array) => {
+ vis.array.set(array, 'HashingDH');
+ vis.array.hideArrayAtIndex(2);
+ },
+ [[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]]
+ );
+
+ return "Success";
+ },
+};
diff --git a/src/algorithms/controllers/HashingInsert.js b/src/algorithms/controllers/HashingInsert.js
deleted file mode 100644
index e69de29bb..000000000
diff --git a/src/algorithms/controllers/HashingLP.js b/src/algorithms/controllers/HashingLP.js
new file mode 100644
index 000000000..cac94d792
--- /dev/null
+++ b/src/algorithms/controllers/HashingLP.js
@@ -0,0 +1,27 @@
+import Array2DTracer from '../../components/DataStructures/Array/Array2DTracer';
+import { HashingExp } from '../explanations';
+
+export default {
+ explanation: HashingExp,
+ initVisualisers() {
+ return {
+ array: {
+ instance: new Array2DTracer('array', null, 'Hash Table'),
+ order: 0,
+ },
+ };
+ },
+
+ run(chunker) {
+ chunker.add(
+ 'HashInit(T)',
+ (vis, array) => {
+ vis.array.set(array, 'HashingLP');
+ vis.array.hideArrayAtIndex(2);
+ },
+ [[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]]
+ );
+
+ return "Success";
+ },
+};
diff --git a/src/algorithms/controllers/HashingSearch.js b/src/algorithms/controllers/HashingSearch.js
deleted file mode 100644
index e69de29bb..000000000
diff --git a/src/algorithms/controllers/index.js b/src/algorithms/controllers/index.js
index d808d469a..06db8db00 100644
--- a/src/algorithms/controllers/index.js
+++ b/src/algorithms/controllers/index.js
@@ -20,5 +20,5 @@ export { default as DFSrec } from './DFSrec';
export { default as prim_old } from './prim_old';
export { default as prim } from './prim';
export { default as kruskal } from './kruskal';
-export { default as HashingInsert } from './HashingInsert';
-export { default as HashingSearch } from './HashingSearch';
+export { default as HashingLP } from './HashingLP';
+export { default as HashingDH } from './HashingDH';
diff --git a/src/algorithms/index.js b/src/algorithms/index.js
index 92abfa734..951818c4d 100644
--- a/src/algorithms/index.js
+++ b/src/algorithms/index.js
@@ -153,39 +153,35 @@ const allalgs = {
},
},
- 'Hashing (LP)': {
+ 'HashingLP': {
name: 'Hashing (linear probing)',
category: 'Insert/Search',
- param: ,
+ param: ,
instructions: Instructions.HashingInstruction,
explanation: Explanation.HashingExp,
extraInfo: ExtraInfo.HashingInfo,
pseudocode: {
- insertion: Pseudocode.HashingInsert,
- search: Pseudocode.HashingSearch,
+ hash: Pseudocode.HashingLP,
},
controller: {
- insertion: Controller.HashingInsert,
- search: Controller.HashingSearch,
+ hash: Controller.HashingLP,
},
},
- '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,
- },
+ 'HashingDH': {
+ name: 'Hashing (double hashing)',
+ category: 'Insert/Search',
+ param: ,
+ instructions: Instructions.HashingInstruction,
+ explanation: Explanation.HashingExp,
+ extraInfo: ExtraInfo.HashingInfo,
+ pseudocode: {
+ hash: Pseudocode.HashingDH,
+ },
+ controller: {
+ hash: Controller.HashingDH,
},
+ },
'DFSrec': {
name: 'Depth First Search',
diff --git a/src/algorithms/parameters/HashingParam.js b/src/algorithms/parameters/HashingDHParam.js
similarity index 83%
rename from src/algorithms/parameters/HashingParam.js
rename to src/algorithms/parameters/HashingDHParam.js
index 46a69d142..0c42739b2 100644
--- a/src/algorithms/parameters/HashingParam.js
+++ b/src/algorithms/parameters/HashingDHParam.js
@@ -39,8 +39,9 @@ const BlueRadio = withStyles({
//const ERROR_TOO_LARGE = `Please enter only ${HASHING_FUNCTION} digits in the table`;
-function HashingParam() {
+function HashingDHParam() {
const [message, setMessage] = useState(null);
+ const { algorithm, dispatch } = useContext(GlobalContext);
const [array, setArray] = useState(DEFAULT_ARRAY);
const [search, setSearch] = useState(DEFAULT_SEARCH);
const [size, setSize] = useState({
@@ -49,15 +50,24 @@ function HashingParam() {
});
const handleChange = (e) => {
- setSize({ ...UNCHECKED, [e.target.name]: true })
- }
-
- useEffect(
- () => {
- document.getElementById('startBtnGrp').click();
- },
- [size],
- );
+ // setSize({ ...UNCHECKED, [e.target.name]: true })
+ e.preventDefault();
+ const inputValue = e.target[0].value;
+
+ // const visualiser = algorithm.chunker.visualisers;
+ dispatch(GlobalActions.RUN_ALGORITHM, {
+ name: 'HashingDH',
+ mode: 'hash',
+ // visualiser,
+ });
+ }
+
+ useEffect(
+ () => {
+ document.getElementById('startBtnGrp').click();
+ },
+ [size],
+ );
return (
@@ -72,6 +82,7 @@ function HashingParam() {
SET_VAL = {setArray}
ALGORITHM_NAME = {HASHING_INSERT}
EXAMPLE={HASHING_EXAMPLE}
+ handleSubmit={handleChange}
setMessage={setMessage}
/>
@@ -114,4 +125,4 @@ function HashingParam() {
);
}
-export default HashingParam;
+export default HashingDHParam;
diff --git a/src/algorithms/parameters/HashingLPParam.js b/src/algorithms/parameters/HashingLPParam.js
new file mode 100644
index 000000000..7be9804bc
--- /dev/null
+++ b/src/algorithms/parameters/HashingLPParam.js
@@ -0,0 +1,128 @@
+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 {genUniqueRandNumList} from './helpers/ParamHelper';
+
+// import useParam from '../../context/useParam';
+
+const ALGORITHM_NAME = 'Hashing';
+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 HashingLPParam() {
+ const [message, setMessage] = useState(null);
+ const { algorithm, dispatch } = useContext(GlobalContext);
+ 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 })
+ e.preventDefault();
+ const inputValue = e.target[0].value;
+
+ // const visualiser = algorithm.chunker.visualisers;
+ dispatch(GlobalActions.RUN_ALGORITHM, {
+ name: 'HashingLP',
+ mode: 'hash',
+ // visualiser,
+ });
+ }
+
+ useEffect(
+ () => {
+ document.getElementById('startBtnGrp').click();
+ },
+ [size],
+ );
+
+
+ return (
+ <>
+
+
+
+
+ {}
+
+
+
+ }
+ label="Small Table"
+ className="checkbox"
+ />
+
+ }
+ label="Large Table"
+ className="checkbox"
+ />
+ >
+ );
+}
+
+export default HashingLPParam;
diff --git a/src/algorithms/parameters/index.js b/src/algorithms/parameters/index.js
index f370aa2db..283998b05 100644
--- a/src/algorithms/parameters/index.js
+++ b/src/algorithms/parameters/index.js
@@ -18,4 +18,5 @@ export { default as ASTARParam } from './ASTParam';
export { default as BFSParam } from './BFSParam';
export { default as DFSParam } from './DFSParam';
export { default as DFSrecParam } from './DFSrecParam';
-export { default as HashingParam } from './HashingParam';
+export { default as HashingLPParam } from './HashingLPParam';
+export { default as HashingDHParam } from './HashingDHParam';
diff --git a/src/algorithms/pseudocode/HashingSearch.js b/src/algorithms/pseudocode/HashingDH.js
similarity index 96%
rename from src/algorithms/pseudocode/HashingSearch.js
rename to src/algorithms/pseudocode/HashingDH.js
index 7eadd7928..0fb9ddbd8 100644
--- a/src/algorithms/pseudocode/HashingSearch.js
+++ b/src/algorithms/pseudocode/HashingDH.js
@@ -3,7 +3,7 @@ import parse from '../../pseudocode/parse';
export default parse(`
\\Code{
Main
- HashSearch(T, k) // Search for key k in table T
+ HashSearch(T, k) // Search for key k in table T \\B HashSearch(T, k)
\\In{
i <- hash(k) \\Ref Hash1
Choose Increment value for stepping through T \\Ref SetIncrementLinearProbing
@@ -56,4 +56,4 @@ export default parse(`
BIGPRIME2=1429, SMALLISHPRIME=23
\\Expl}
\\Code}
-`);
\ No newline at end of file
+`);
diff --git a/src/algorithms/pseudocode/HashingInsert.js b/src/algorithms/pseudocode/HashingLP.js
similarity index 98%
rename from src/algorithms/pseudocode/HashingInsert.js
rename to src/algorithms/pseudocode/HashingLP.js
index df3f06f63..3836f074c 100644
--- a/src/algorithms/pseudocode/HashingInsert.js
+++ b/src/algorithms/pseudocode/HashingLP.js
@@ -4,7 +4,7 @@ export default parse(`
\\Code{
Main
- HashInit(T) // TableSize is prime
+ HashInit(T) // TableSize is prime \\B HashInit(T)
\\In{
Initialize Hash Table Slots to Empty \\Ref NullTable
Insertions <- 0 // Keep track of how full table is \\Ref Insert
diff --git a/src/algorithms/pseudocode/index.js b/src/algorithms/pseudocode/index.js
index b53afb371..32bd5066f 100644
--- a/src/algorithms/pseudocode/index.js
+++ b/src/algorithms/pseudocode/index.js
@@ -20,5 +20,5 @@ export { default as AStar } from './AStar';
export { default as BFS } from './BFS';
export { default as DFS } from './DFS';
export { default as DFSrec } from './DFSrec';
-export { default as HashingInsert } from './HashingInsert';
-export { default as HashingSearch } from './HashingSearch';
+export { default as HashingLP } from './HashingLP';
+export { default as HashingDH } from './HashingDH';