From ea4c7c2b7209aea0879ee95e43233412ff23cbeb Mon Sep 17 00:00:00 2001 From: spidunno Date: Mon, 27 May 2024 20:36:53 -0400 Subject: [PATCH] change to better resizable panels library and make default algorithm quicksort --- bun.lockb | Bin 51875 -> 51890 bytes package.json | 2 +- src/App.tsx | 30 ++++++++++++--------- src/business/commands.ts | 5 +++- src/defaultScript.ts | 57 ++++++++++++++++++++------------------- src/index.css | 10 +++++++ 6 files changed, 62 insertions(+), 42 deletions(-) diff --git a/bun.lockb b/bun.lockb index 4e73edd8f32f42923d69bcda3b8a22b51789c73a..4b0d072fb0bc5e0b48a35d8196c8fe78617fd18f 100755 GIT binary patch delta 4610 zcmai14OEm>8vgDulQW`%fa2#2DvIc+j10p73i6Sup@EuYnw5(DOVn{pNGpbGEZE=RVK-zW2WO ze)qoj-uE^)gtRt<)Y)RG`<9~Tvpar%aO=(G-&~sPTmFyn)wQ?J(Ef=0L9PuKyaVf} zjOlKcB(JB`?J7(t@i^<{@50jvS?_KO1YG$8LM6^K!-_6`H#!&zMFSz6%nNXvSv z@&X`ydl%&|Ds>e~QjurgGMBqh%7{`w&kBr$y%!KaZ%9CY4N5Mb2XgyK6nvWg6wvPk z^69D;@@mPu3?v$gIRQfs5I=7k3hpQ#$Q?ukm4Q9m#npKo~thBT0HV2P*5Q-H;d#{BT9ZwK;)dke@1$mfmY8LSWQ zumg^I09~Gh<@58GN`HgQJ32zKAtP6JU=_I34h#c6>&A}y+zip z3VVQDC|@LBSHnv8}j zXo@MJTe{&I*i6pYgJkWl7<~6hQihPfCLiQvEc!ShuOMp=h2@b8=f7>!E6XOmDPZuMMQ@Fo@yduN*%y%uo=7o`-!ZP3QHzeq+)swu{RcT!N}e<6?5f} zRCGNeXjoJx%OzKoVwj9IA4dzL(hVEICJ6Q^ShipTu;8k-5KPszfT{JqyJtFEAD`;g20AS6?1dzP^f~5ZiN>2!;b-W5r^RB9~cV3&@A^Tk@k+$ZAno6}eDe zBA-Pu*%0^RFqH->3r%H9$Q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za9d+k?8&6|2_gL|>O}u_)U{TUwPbqkV?P=rt>*7SwT_TdD`jZOcXjxI`LlaG{%lCE zrRS7$qyK`Moz)@D9TRP=?JaBh{0HCptt)?5NTCWbbi7s)?R23w*=U7dvYgFEk#&;H zQ)w1a&fRuAxi@C5dOA`a&UAi4X=+^`oTIurcAD_jb;@+0t~Uht=3aEM&XTUB*mK4d zb?vvd@H`B-)aalk;dgtKEWDp~x}NVed^$}yN%qZ>{7d>21QYjWm#ih9BhEE_ma(vT z1KOuJT$%8OR_d`sO4pK9q4emH!%=e2r0%QBF3pG(!sEtn3 zNbw6YZ7G!h&k*!%2wP~=c1hM=5g$GFLv%!B=h=|eGt{<)x$ULx4+p|KqO7fHKi?E} zcxs8|mpcy5g`1GIH_EZ4i5G5EK4A{^%8#k;hj5y@Eft|@{WeKGx#D3uhV!dES~fNw zEc|KJCv0um{gI9vlK#ETB?lid{<%vB>aXFMzeQFvUcy5?f4|J zqI%qR=+hjja3!IhXvcV2dnLIx7p*wHd+#cpSb%pE@_E0P?xDT*s(PdMsf%aM+-DaE zypZ{M4GpSyWoXZF-`dglTVEcq5_+~`PTcMo8D0&3t>-B5dst>k!_SVHge2lxj>6Y_q|M`3xxF9mryO-ak+WXA(w&TES?p;@OVyc7Pbb_G0;O_r*`BDE*8`Ah7 zaLfgPEtR=1LaZ}Yd(N$TyTG4we9a}^1wS{fRJBvRP|fuE&ML8hoDIFit~93M9s1@# rEG6$UTL;+(saeRf5}#*#e86 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