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
23 changes: 20 additions & 3 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/algorithms/instructions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ const hashingInstructions2 = [
- x : Insert x into table.
- x - y: Bulk insert from integers x to y.
- x - y - z: Bulk insert from integers x to y in steps of z.
- -x: Delete x from table.`,
- -x: Delete x from table.

If you wish to input more integers, select the Expand radio button.
The table will now expand after reaching 80% capacity`,

`Click on ${KEY_INSERT} to enter Insert mode and load the algorithm.`,
`Click on ${KEY_PLAY} to watch the algorithm run. The speed may be adjusted using the speed slider.`,
],
Expand Down
34 changes: 27 additions & 7 deletions src/algorithms/parameters/HashingDHParam.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import PropTypes from 'prop-types';
import { withAlgorithmParams } from './helpers/urlHelpers'

import { URLContext } from '../../context/urlState.js';

import React, { useState, useContext, useEffect } from 'react';
import { GlobalContext } from '../../context/GlobalState';
import { GlobalActions } from '../../context/actions';
Expand Down Expand Up @@ -56,16 +61,23 @@ const ERROR_INVALID_RANGES = 'If you had entered ranges, please input valid rang
* Double Hashing input component
* @returns the component
*/
function HashingDHParam() {
function HashingDHParam({ mode, list, value }) {
const [message, setMessage] = useState(null);
const { algorithm, dispatch } = useContext(GlobalContext);
const [array, setArray] = useState(DEFAULT_ARRAY);
const [search, setSearch] = useState(DEFAULT_SEARCH);
const [array, setLocalArray] = useState(list || DEFAULT_ARRAY);
const [search, setLocalSearch] = useState(DEFAULT_SEARCH);
const [HASHSize, setHashSize] = useState({
smallTable: true,
largeTable: false,
});

const [expand, setExpand] = useState(DEFAULT_EXPAND);
const { setNodes, setSearchValue } = useContext(URLContext);

useEffect(() => {
setNodes(array);
setSearchValue(search);
}, [array, search])

/**
* Handle changes to input
Expand Down Expand Up @@ -171,7 +183,7 @@ function HashingDHParam() {
mode="insertion"
formClassName="formLeft"
DEFAULT_VAL = {array}
SET_VAL = {setArray}
SET_VAL = {setLocalArray}
REFRESH_FUNCTION={
(() => {
if (HASHSize.smallTable) {
Expand All @@ -194,8 +206,8 @@ function HashingDHParam() {
buttonName="SEARCH"
mode="search"
formClassName="formRight"
DEFAULT_VAL = {DEFAULT_SEARCH}
SET_VAL = {setSearch}
DEFAULT_VAL = {value || DEFAULT_SEARCH}
SET_VAL = {setLocalSearch}
ALGORITHM_NAME = {HASHING_SEARCH}
handleSubmit={handleSearch}
setMessage={setMessage}
Expand Down Expand Up @@ -254,4 +266,12 @@ function HashingDHParam() {
);
}

export default HashingDHParam;
// Define the prop types for URL Params
HashingDHParam.propTypes = {
alg: PropTypes.string.isRequired, // keep alg for all algorithms
mode: PropTypes.string.isRequired, //keep mode for all algorithms
list: PropTypes.string.isRequired,
value: PropTypes.string.isRequired
};
export default withAlgorithmParams(HashingDHParam);

33 changes: 26 additions & 7 deletions src/algorithms/parameters/HashingLPParam.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import PropTypes from 'prop-types';
import { withAlgorithmParams } from './helpers/urlHelpers'

import { URLContext } from '../../context/urlState.js';

import React, { useState, useContext, useEffect } from 'react';
import { GlobalContext } from '../../context/GlobalState';
import { GlobalActions } from '../../context/actions';
Expand Down Expand Up @@ -56,16 +61,23 @@ const ERROR_INVALID_RANGES = 'If you had entered ranges, please input valid rang
* Linear probing input component
* @returns the component
*/
function HashingLPParam() {
function HashingLPParam({ mode, list, value }) {
const [message, setMessage] = useState(null);
const { algorithm, dispatch } = useContext(GlobalContext);
const [array, setArray] = useState(DEFAULT_ARRAY);
const [search, setSearch] = useState(DEFAULT_SEARCH);
const [array, setLocalArray] = useState(list || DEFAULT_ARRAY);
const [search, setLocalSearch] = useState(DEFAULT_SEARCH);
const [HASHSize, setHashSize] = useState({
smallTable: true,
largeTable: false,
});
const [expand, setExpand] = useState(DEFAULT_EXPAND);
const { setNodes, setSearchValue } = useContext(URLContext);

useEffect(() => {
setNodes(array);
setSearchValue(search);
}, [array, search])


/**
* Handle changes to input
Expand Down Expand Up @@ -170,7 +182,7 @@ function HashingLPParam() {
mode="insertion"
formClassName="formLeft"
DEFAULT_VAL = {array}
SET_VAL = {setArray}
SET_VAL = {setLocalArray}
REFRESH_FUNCTION={
(() => {
if (HASHSize.smallTable) {
Expand All @@ -193,8 +205,8 @@ function HashingLPParam() {
buttonName="SEARCH"
mode="search"
formClassName="formRight"
DEFAULT_VAL = {DEFAULT_SEARCH}
SET_VAL = {setSearch}
DEFAULT_VAL = {value || DEFAULT_SEARCH}
SET_VAL = {setLocalSearch}
ALGORITHM_NAME = {HASHING_SEARCH}
handleSubmit={handleSearch}
setMessage={setMessage}
Expand Down Expand Up @@ -253,4 +265,11 @@ function HashingLPParam() {
);
}

export default HashingLPParam;
// Define the prop types for URL Params
HashingLPParam.propTypes = {
alg: PropTypes.string.isRequired, // keep alg for all algorithms
mode: PropTypes.string.isRequired, //keep mode for all algorithms
list: PropTypes.string.isRequired,
value: PropTypes.string.isRequired
};
export default withAlgorithmParams(HashingLPParam);