Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/algorithms/controllers/HashingCommon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Array2DTracer from '../../components/DataStructures/Array/Array2DTracer';

25 changes: 25 additions & 0 deletions src/algorithms/controllers/HashingDH.js
Original file line number Diff line number Diff line change
@@ -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";
},
};
Empty file.
27 changes: 27 additions & 0 deletions src/algorithms/controllers/HashingLP.js
Original file line number Diff line number Diff line change
@@ -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";
},
};
Empty file.
4 changes: 2 additions & 2 deletions src/algorithms/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
38 changes: 17 additions & 21 deletions src/algorithms/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,39 +153,35 @@ const allalgs = {
},
},

'Hashing (LP)': {
'HashingLP': {
name: 'Hashing (linear probing)',
category: 'Insert/Search',
param: <Param.HashingParam/>,
param: <Param.HashingLPParam/>,
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: <Param.HashingParam/>,
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: <Param.HashingDHParam/>,
instructions: Instructions.HashingInstruction,
explanation: Explanation.HashingExp,
extraInfo: ExtraInfo.HashingInfo,
pseudocode: {
hash: Pseudocode.HashingDH,
},
controller: {
hash: Controller.HashingDH,
},
},

'DFSrec': {
name: 'Depth First Search',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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 (
Expand All @@ -72,6 +82,7 @@ function HashingParam() {
SET_VAL = {setArray}
ALGORITHM_NAME = {HASHING_INSERT}
EXAMPLE={HASHING_EXAMPLE}
handleSubmit={handleChange}
setMessage={setMessage}
/>

Expand Down Expand Up @@ -114,4 +125,4 @@ function HashingParam() {
);
}

export default HashingParam;
export default HashingDHParam;
128 changes: 128 additions & 0 deletions src/algorithms/parameters/HashingLPParam.js
Original file line number Diff line number Diff line change
@@ -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) => <Radio {...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 (
<>
<div className="form">
<ListParam
name="Hashing"
buttonName="INSERT"
mode="insertion"
formClassName="formLeft"
DEFAULT_VAL = {array}
SET_VAL = {setArray}
ALGORITHM_NAME = {HASHING_INSERT}
EXAMPLE={HASHING_EXAMPLE}
handleSubmit={handleChange}
setMessage={setMessage}
/>


{<SingleValueParam
name="Hashing"
buttonName="SEARCH"
mode="search"
formClassName="formRight"
DEFAULT_VAL = {DEFAULT_SEARCH}
SET_VAL = {setSearch}
ALGORITHM_NAME = {HASHING_SEARCH}
setMessage={setMessage}
/>}
</div>

<FormControlLabel
control={
<BlueRadio
checked={size.smallTable}
onChange={handleChange}
name="smallTable"
/>
}
label="Small Table"
className="checkbox"
/>
<FormControlLabel
control={
<BlueRadio
checked={size.largeTable}
onChange={handleChange}
name="largeTable"
/>
}
label="Large Table"
className="checkbox"
/>
</>
);
}

export default HashingLPParam;
3 changes: 2 additions & 1 deletion src/algorithms/parameters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -56,4 +56,4 @@ export default parse(`
BIGPRIME2=1429, SMALLISHPRIME=23
\\Expl}
\\Code}
`);
`);
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/algorithms/pseudocode/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';