diff --git a/bun.lockb b/bun.lockb index 4e73edd..4b0d072 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index eefd245..0e022e7 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "lucide-solid": "^0.379.0", "solid-js": "^1.8.15", "solid-monaco": "^0.2.0", - "solid-resizable-panels": "^0.5.4" + "solid-resizable-panels-port": "^0.0.0" }, "devDependencies": { "typescript": "^5.2.2", diff --git a/src/App.tsx b/src/App.tsx index 3f0911a..68396a3 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,7 +1,7 @@ import { MonacoEditor } from "solid-monaco"; import type { Monaco } from '@monaco-editor/loader'; // import { useCallback, useEffect, useRef, useState } from "solid-js"; -import { PanelGroup, Panel, ResizeHandle } from "solid-resizable-panels"; +import { PanelGroup, Panel, PanelResizeHandle } from "solid-resizable-panels-port"; // import { useInterval } from "usehooks-ts"; import defaultScript from "./defaultScript?raw"; import editorExtraTypes from "./types?raw"; @@ -9,7 +9,7 @@ import editorExtraTypes from "./types?raw"; import "./business/audio"; import "./App.css"; -import { visualizeJackieSort } from "./business/commands"; +import { quickSort } from "./business/commands"; import { transformTypescript } from "./ts"; import { createOscillator } from "./business/audio"; // import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; @@ -21,11 +21,11 @@ const JS_EXTRA_FUNCTIONS = transformTypescript(editorExtraTypes); console.log(JS_EXTRA_FUNCTIONS); function setUpMonaco(monaco: Monaco): void { + monaco.editor.setTheme('vs-dark'); monaco.languages.typescript.typescriptDefaults.addExtraLib(editorExtraTypes); } -// let lastScript = ""; export default function App() { - const [itemCount] = createSignal(50); + const [itemCount, setItemCount] = createSignal(50); let interval: ReturnType | null = null; const [swaps, setSwaps] = createSignal(Array(itemCount()).fill(false)); const [sorted, setSorted] = createSignal(Array(itemCount()).fill(false)); @@ -40,9 +40,9 @@ export default function App() { VisualizerCommand, void, number[] - > | null>(visualizeJackieSort(items())); + > | null>(quickSort(items())); - const [commandGeneratorFunction, setCommandGeneratorFunction] = createSignal(visualizeJackieSort); + const [commandGeneratorFunction, setCommandGeneratorFunction] = createSignal(quickSort); const [sortPlaying, setSortPlaying] = createSignal(false); const [muted, setMuted] = createSignal(false); @@ -50,6 +50,9 @@ export default function App() { // useEffect(() => { // if(commandGeneratorFunction) setCommandGenerator(commandGeneratorFunction(items)); // }, [commandGenerator]) + createEffect(() => { + setItems([...Array(itemCount()).keys()].sort(() => Math.random() - 0.5)); + }, [itemCount()]); createEffect(() => { if (interval) clearInterval(interval); const gen = commandGenerator(); @@ -235,12 +238,11 @@ export default function App() { }; return ( - - + + + setItemCount(parseInt(e.target.value))}/> - - + +
{ - let clean = false; +export default function* sort(items: number[]): Generator { + yield* _quicksort(items, 0, items.length - 1); + for (let i = 0; i < items.length; i ++) { + yield cursors([i]); + yield sorted([i]); + } +} + +function* _quicksort(arr: number[], low: number, high: number): Generator { + arr = yield cursors([low, high]); + if (low < high) { + const [pivotIndex, updatedArr] = yield* partition(arr, low, high); + arr = updatedArr; // update the array after partition + yield* _quicksort(arr, low, pivotIndex - 1); + yield* _quicksort(arr, pivotIndex + 1, high); + } +} - let sortedCount = 0; +function* partition(arr: number[], low: number, high: number): Generator { + let pivot = arr[high]; + let i = low - 1; - while (!clean) { - clean = true; - yield notSorted([...Array(items.length).keys()]); - for (let i = 0; i < items.length - 1; i++) { - yield cursors([i, i + 1]); - if (items[i] > items[i + 1]) { - for ( - let j = items.length - ((sortedCount % (items.length - i)) + 1); - j > i; - j-- - ) { - yield cursors([i, j]); - if (items[j] < items[i]) { - // yield notSorted([i, j]); - items = yield swap(i, j); - // yield sorted([i, j]); - break; - } - } - sortedCount += 1; - clean = false; - } else yield sorted([i, i + 1]); + for (let j = low; j < high; j++) { + yield cursors([i, j, high]); + if (arr[j] < pivot) { + i++; + arr = yield swap(i, j); } } -} + arr = yield swap(i + 1, high); + yield sorted([i + 1]); + return [i + 1, arr]; +} \ No newline at end of file diff --git a/src/index.css b/src/index.css index b32813a..b768254 100644 --- a/src/index.css +++ b/src/index.css @@ -11,4 +11,14 @@ body { .list-item { transition: left 0.25s; +} + +#controls > button, #controls > input { + background-color: #121212; + color: white; + border: 1px solid #ffffff20; + margin: 4px; + border-radius: 8px; + min-height: 32px; + height: 32px; } \ No newline at end of file