From 1d6d3e11f62b7c38f3e136948df16e01905babcc Mon Sep 17 00:00:00 2001 From: ROBOT Date: Wed, 16 Jul 2025 23:47:26 +0900 Subject: [PATCH 1/4] build(deps): update zod to version 4.0.5 --- bun.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bun.lock b/bun.lock index 591c16b..44f8633 100644 --- a/bun.lock +++ b/bun.lock @@ -19,7 +19,7 @@ "terser": "^5.43.1", "ts-jest": "^29.3.2", "tsup": "^8.4.0", - "zod": "^3.24.3", + "zod": "^4.0.5", }, "devDependencies": { "@eslint/js": "^9.25.1", @@ -1288,7 +1288,7 @@ "yocto-queue": ["yocto-queue@0.1.0", "", {}, "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q=="], - "zod": ["zod@3.24.3", "", {}, "sha512-HhY1oqzWCQWuUqvBFnsyrtZRhyPeR7SUGv+C4+MsisMuVfSPx8HpwWqH8tRahSlt6M3PiFAcoeFhZAqIXTxoSg=="], + "zod": ["zod@4.0.5", "", {}, "sha512-/5UuuRPStvHXu7RS+gmvRf4NXrNxpSllGwDnCBcJZtQsKrviYXm54yDGV2KYNLT5kq0lHGcl7lqWJLgSaG+tgA=="], "@babel/core/semver": ["semver@6.3.1", "", { "bin": { "semver": "bin/semver.js" } }, "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA=="], From a1271a8404853350d351d109c3b6997cfc5ba067 Mon Sep 17 00:00:00 2001 From: ROBOT Date: Wed, 16 Jul 2025 23:50:16 +0900 Subject: [PATCH 2/4] refactor: remove transpiled options from sorting algorithms --- tests/utils.ts | 62 ++++++++++---------------------------------------- 1 file changed, 12 insertions(+), 50 deletions(-) diff --git a/tests/utils.ts b/tests/utils.ts index 2d849b0..32af2f9 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -1,6 +1,5 @@ import { SortMan } from "../src/index"; import { randomString } from "../src/utils/random"; -import { SortMan as TranspiledSortMan } from "../dist/index.cjs"; import type { Global } from "@jest/types"; import type { SortBase } from "../src/Sort/SortBase"; @@ -13,7 +12,6 @@ export type ObjectArrData = { export type SortOptions = { describe?: () => (blockName: Global.BlockNameLike, blockFn: Global.BlockFn) => void; - transpiled?: SortBase; }; export type Sort = { @@ -59,86 +57,50 @@ export const ignoreSorts = ["Default sort", "Bogo sort"] satisfies string[]; export const sorts: Sorts = [ { name: "Default sort", - algorithm: SortMan as unknown as SortBase, - options: { - transpiled: TranspiledSortMan as unknown as SortBase - } + algorithm: SortMan as unknown as SortBase }, { name: "Bogo sort", - algorithm: SortMan.bogo, - options: { - transpiled: TranspiledSortMan.bogo as unknown as SortBase - } + algorithm: SortMan.bogo }, { name: "Bubble sort", - algorithm: SortMan.bubble, - options: { - transpiled: TranspiledSortMan.bubble as unknown as SortBase - } + algorithm: SortMan.bubble }, { name: "Quick sort", - algorithm: SortMan.quick, - options: { - transpiled: TranspiledSortMan.quick as unknown as SortBase - } + algorithm: SortMan.quick }, { name: "Merge sort", - algorithm: SortMan.merge, - options: { - transpiled: TranspiledSortMan.merge as unknown as SortBase - } + algorithm: SortMan.merge }, { name: "Insertion sort", - algorithm: SortMan.insertion, - options: { - transpiled: TranspiledSortMan.insertion as unknown as SortBase - } + algorithm: SortMan.insertion }, { name: "Selection sort", - algorithm: SortMan.selection, - options: { - transpiled: TranspiledSortMan.selection as unknown as SortBase - } + algorithm: SortMan.selection }, { name: "Heap sort", - algorithm: SortMan.heap, - options: { - transpiled: TranspiledSortMan.heap as unknown as SortBase - } + algorithm: SortMan.heap }, { name: "Shell sort", - algorithm: SortMan.shell, - options: { - transpiled: TranspiledSortMan.shell as unknown as SortBase - } + algorithm: SortMan.shell }, { name: "Bucket sort", - algorithm: SortMan.bucket, - options: { - transpiled: TranspiledSortMan.bucket as unknown as SortBase - } + algorithm: SortMan.bucket }, { name: "Comb sort", - algorithm: SortMan.comb, - options: { - transpiled: TranspiledSortMan.comb as unknown as SortBase - } + algorithm: SortMan.comb }, { name: "Gnome sort", - algorithm: SortMan.gnome, - options: { - transpiled: TranspiledSortMan.gnome as unknown as SortBase - } + algorithm: SortMan.gnome } ]; From 898048feb67fd9b9ee26ac6513401d3bd9e76a1f Mon Sep 17 00:00:00 2001 From: ROBOT Date: Thu, 17 Jul 2025 00:04:08 +0900 Subject: [PATCH 3/4] feat: add ShakerSort algorithm and integrate into SortMan --- .changeset/wet-times-slide.md | 5 ++++ src/Sort/ShakerSort.ts | 50 +++++++++++++++++++++++++++++++++++ src/index.ts | 2 ++ tests/utils.ts | 4 +++ 4 files changed, 61 insertions(+) create mode 100644 .changeset/wet-times-slide.md create mode 100644 src/Sort/ShakerSort.ts diff --git a/.changeset/wet-times-slide.md b/.changeset/wet-times-slide.md new file mode 100644 index 0000000..a9d19b8 --- /dev/null +++ b/.changeset/wet-times-slide.md @@ -0,0 +1,5 @@ +--- +"sortman": minor +--- + +feat: add ShakerSort algorithm and integrate into SortMan diff --git a/src/Sort/ShakerSort.ts b/src/Sort/ShakerSort.ts new file mode 100644 index 0000000..89cd7d7 --- /dev/null +++ b/src/Sort/ShakerSort.ts @@ -0,0 +1,50 @@ +import { swap } from "../utils/swap"; +import { SortBase, type SortCoreElement } from "./SortBase"; + +export class ShakerSort extends SortBase { + private asc(arr: SortCoreElement, start: number, end: number) { + if (start < end) { + if ( + (arr[start] as SortCoreElement[number]).num > + (arr[start + 1] as SortCoreElement[number]).num + ) { + swap(start, start + 1, arr); + } + this.asc(arr, start + 1, end); + } + return arr; + } + + private desc(arr: SortCoreElement, start: number, end: number) { + if (end > start) { + if ( + (arr[end - 1] as SortCoreElement[number]).num > + (arr[end] as SortCoreElement[number]).num + ) { + swap(end - 1, end, arr); + } + this.desc(arr, start, end - 1); + } + return arr; + } + + public core(content: SortCoreElement): SortCoreElement { + let arr = content.concat(); + let start = 0; + let end = arr.length - 1; + + while (true) { + arr = this.asc(arr, start, end); + end--; + if (start === end) { + break; + } + arr = this.desc(arr, start, end); + start++; + if (start === end) { + break; + } + } + return arr; + } +} diff --git a/src/index.ts b/src/index.ts index 8a8bfd6..3a1d30d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,6 +9,7 @@ import { ShellSort } from "./Sort/ShellSort"; import { BucketSort } from "./Sort/BucketSort"; import { CombSort } from "./Sort/CombSort"; import { GnomeSort } from "./Sort/GnomeSort"; +import { ShakerSort } from "./Sort/ShakerSort"; import type { SortOptions } from "./Sort/SortBase"; @@ -23,6 +24,7 @@ export class SortMan { public static readonly merge = new MergeSort(); public static readonly quick = new QuickSort(); public static readonly selection = new SelectionSort(); + public static readonly shaker = new ShakerSort(); public static readonly shell = new ShellSort(); public static sort(arr: T[]): T[]; diff --git a/tests/utils.ts b/tests/utils.ts index 32af2f9..09ecf5b 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -102,5 +102,9 @@ export const sorts: Sorts = [ { name: "Gnome sort", algorithm: SortMan.gnome + }, + { + name: "Shaker sort", + algorithm: SortMan.shaker } ]; From 7a5fc8abe1fff0649feb780e647290246acc5b00 Mon Sep 17 00:00:00 2001 From: ROBOT Date: Thu, 17 Jul 2025 00:05:13 +0900 Subject: [PATCH 4/4] docs: add Shaker sort to supported sorts list in README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 78a4dcf..32b0575 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,7 @@ console.log(sorted); - Merge sort - `SortMan.merge` - Quick sort - `SortMan.quick` - Selection sort - `SortMan.selection` +- Shaker sort - `SortMan.shaker` - Shell sort - `SortMan.shell` # Options