better comments

This commit is contained in:
Baipyrus 2024-05-21 20:07:15 +02:00
parent 668e2a6190
commit fc3605034f

View File

@ -34,6 +34,7 @@
// Start continuous animation
interv = setInterval(animate, 1000 / FPS);
// Assign first job over the entire array
queue.push(new Job(data, 0, data.length));
});
@ -91,8 +92,10 @@
* @returns {Response|void}
*/
step() {
// Base case, end condition
if (this.start >= this.end - 1 || this.start < 0) return new Response(true, null, null, null);
// Comparator reached end of range, swap pivot
if (this.compr >= this.end - 1) {
[this.array[this.index], this.array[this.end - 1]] = [
this.array[this.end - 1],
@ -102,6 +105,7 @@
return new Response(false, this.index, this.start, this.end);
}
// Compare with pivot to split range in two
if (this.array[this.compr] <= this.pivot) {
[this.array[this.index], this.array[this.compr]] = [
this.array[this.compr],
@ -123,15 +127,18 @@
context.fillStyle = 'white';
data.forEach((d, i) => {
let color = 'white';
// Try chosing color based on all job indecies
queue.forEach((q) => {
const { index, compr } = q;
if (i === index) color = 'red';
else if (i === compr) color = 'lime';
});
// Display datapoint with chosen color
context.fillStyle = color;
context.fillRect(i * width, canvas.height, width - 1, -d * canvas.height);
});
// Step job and handle result
const result = queue[0].step();
if (result) {
queue.shift();