Change expected/max calculation when changing the dataset

This commit is contained in:
NunoSempere 2021-11-28 15:46:54 +00:00
parent 56bab8f861
commit 2b9ce6e142

View File

@ -52,8 +52,8 @@ export default function ComparisonView({ listOfElementsForView }) {
let initialShowComparisons = false let initialShowComparisons = false
let initialShowChangeDataSet = false let initialShowChangeDataSet = false
let initialNumSteps = 0; let initialNumSteps = 0;
let maxSteps = maxMergeSortSteps(listOfElementsForView.length) let initialMaxSteps = maxMergeSortSteps(listOfElementsForView.length)
let expectedSteps = expectedNumMergeSortSteps(listOfElementsForView.length) let initialExpectedSteps = expectedNumMergeSortSteps(listOfElementsForView.length)
//let listOfElements = listOfElementsForView.map((element, i) => ({...element, id: i})) //let listOfElements = listOfElementsForView.map((element, i) => ({...element, id: i}))
//let list = increasingList(listOfElementsForView.length) // [0,1,2,3,4] //let list = increasingList(listOfElementsForView.length) // [0,1,2,3,4]
@ -77,7 +77,8 @@ export default function ComparisonView({ listOfElementsForView }) {
let [showComparisons, changeShowComparisons] = useState(initialShowComparisons); let [showComparisons, changeShowComparisons] = useState(initialShowComparisons);
let [showChangeDataSet, changeshowChangeDataSet] = useState(initialShowChangeDataSet); let [showChangeDataSet, changeshowChangeDataSet] = useState(initialShowChangeDataSet);
let [numSteps, increaseNumSteps] = useState(initialNumSteps); let [numSteps, increaseNumSteps] = useState(initialNumSteps);
let [maxSteps, changeMaxSteps] = useState(initialMaxSteps)
let [expectedSteps, changeExpectedSteps] = useState(initialExpectedSteps)
let restart = (posList) => { let restart = (posList) => {
setToComparePair([posList[posList.length - 2], posList[posList.length - 1]]) setToComparePair([posList[posList.length - 2], posList[posList.length - 1]])
@ -93,9 +94,15 @@ export default function ComparisonView({ listOfElementsForView }) {
listOfElementsNew = listOfElementsNew =
listOfElementsNew.map((element, i) => ({ ...element, id: i })) listOfElementsNew.map((element, i) => ({ ...element, id: i }))
let newPosList = increasingList(listOfElementsNew.length) let newPosList = increasingList(listOfElementsNew.length)
let newListLength = listOfElementsNew.length
setListOfElements(listOfElementsNew) setListOfElements(listOfElementsNew)
setPosList(increasingList(listOfElementsNew.length)) setPosList(increasingList(listOfElementsNew.length))
setToComparePair([newPosList[newPosList.length - 2], newPosList[newPosList.length - 1]]) setToComparePair([newPosList[newPosList.length - 2], newPosList[newPosList.length - 1]])
changeExpectedSteps(expectedNumMergeSortSteps(newListLength))
changeMaxSteps(maxMergeSortSteps(newListLength))
restart(newPosList) restart(newPosList)
} }