From 171250248f50bc39fc8ab0cf511907790081d791 Mon Sep 17 00:00:00 2001 From: Tomas Zijdemans Date: Sun, 12 Apr 2026 12:47:34 +0200 Subject: [PATCH 1/5] feat(data-structures): stabilize `Deque` --- async/unstable_channel.ts | 2 +- data_structures/deno.json | 4 +- .../{unstable_deque.ts => deque.ts} | 104 +++++------------- .../{unstable_deque_test.ts => deque_test.ts} | 2 +- data_structures/mod.ts | 1 + 5 files changed, 33 insertions(+), 80 deletions(-) rename data_structures/{unstable_deque.ts => deque.ts} (88%) rename data_structures/{unstable_deque_test.ts => deque_test.ts} (99%) diff --git a/async/unstable_channel.ts b/async/unstable_channel.ts index b82837a685bd..80120a96de0d 100644 --- a/async/unstable_channel.ts +++ b/async/unstable_channel.ts @@ -1,7 +1,7 @@ // Copyright 2018-2026 the Deno authors. MIT license. // This module is browser compatible. -import { Deque } from "@std/data-structures/unstable-deque"; +import { Deque } from "../data_structures/deque.ts"; /** Internal node for the FIFO sender waiting queue. */ interface SenderNode { diff --git a/data_structures/deno.json b/data_structures/deno.json index da895e9caadc..162dba4cf500 100644 --- a/data_structures/deno.json +++ b/data_structures/deno.json @@ -1,6 +1,6 @@ { "name": "@std/data-structures", - "version": "1.0.10", + "version": "1.1.0", "exports": { ".": "./mod.ts", "./unstable-bidirectional-map": "./unstable_bidirectional_map.ts", @@ -11,6 +11,6 @@ "./red-black-tree": "./red_black_tree.ts", "./unstable-2d-array": "./unstable_2d_array.ts", "./unstable-rolling-counter": "./unstable_rolling_counter.ts", - "./unstable-deque": "./unstable_deque.ts" + "./deque": "./deque.ts" } } diff --git a/data_structures/unstable_deque.ts b/data_structures/deque.ts similarity index 88% rename from data_structures/unstable_deque.ts rename to data_structures/deque.ts index 604cda924a9f..9fc93c146729 100644 --- a/data_structures/unstable_deque.ts +++ b/data_structures/deque.ts @@ -9,8 +9,6 @@ const MIN_SHRINK_CAPACITY = 64; * following the `ReadonlyArray` / `ReadonlyMap` / `ReadonlySet` pattern. * A `Deque` is directly assignable to `ReadonlyDeque`. * - * @experimental **UNSTABLE**: New API, yet to be vetted. - * * @typeParam T The type of the values stored in the deque. */ export type ReadonlyDeque = Pick< @@ -65,11 +63,9 @@ function nextPowerOfTwo(n: number): number { * | toArray() | O(n) | O(n) | * | Deque.from() | O(n) | O(n) | * - * @experimental **UNSTABLE**: New API, yet to be vetted. - * * @example Usage * ```ts - * import { Deque } from "@std/data-structures/unstable-deque"; + * import { Deque } from "@std/data-structures/deque"; * import { assertEquals } from "@std/assert"; * * const deque = new Deque(); @@ -95,11 +91,9 @@ export class Deque implements Iterable, ReadonlyDeque { /** * Creates an empty deque, optionally populated from an iterable. * - * @experimental **UNSTABLE**: New API, yet to be vetted. - * * @example Creating an empty deque * ```ts - * import { Deque } from "@std/data-structures/unstable-deque"; + * import { Deque } from "@std/data-structures/deque"; * import { assertEquals } from "@std/assert"; * * const deque = new Deque(); @@ -108,7 +102,7 @@ export class Deque implements Iterable, ReadonlyDeque { * * @example Creating a deque from an iterable * ```ts - * import { Deque } from "@std/data-structures/unstable-deque"; + * import { Deque } from "@std/data-structures/deque"; * import { assertEquals } from "@std/assert"; * * const deque = new Deque([1, 2, 3]); @@ -167,11 +161,9 @@ export class Deque implements Iterable, ReadonlyDeque { /** * The number of elements in the deque. * - * @experimental **UNSTABLE**: New API, yet to be vetted. - * * @example Getting the length * ```ts - * import { Deque } from "@std/data-structures/unstable-deque"; + * import { Deque } from "@std/data-structures/deque"; * import { assertEquals } from "@std/assert"; * * const deque = new Deque([1, 2, 3]); @@ -187,11 +179,9 @@ export class Deque implements Iterable, ReadonlyDeque { /** * Checks if the deque contains no elements. * - * @experimental **UNSTABLE**: New API, yet to be vetted. - * * @example Checking if the deque is empty * ```ts - * import { Deque } from "@std/data-structures/unstable-deque"; + * import { Deque } from "@std/data-structures/deque"; * import { assertEquals } from "@std/assert"; * * const deque = new Deque(); @@ -210,11 +200,9 @@ export class Deque implements Iterable, ReadonlyDeque { /** * Append one or more values to the back of the deque. * - * @experimental **UNSTABLE**: New API, yet to be vetted. - * * @example Pushing values to the back * ```ts - * import { Deque } from "@std/data-structures/unstable-deque"; + * import { Deque } from "@std/data-structures/deque"; * import { assertEquals } from "@std/assert"; * * const deque = new Deque(); @@ -243,11 +231,9 @@ export class Deque implements Iterable, ReadonlyDeque { * in argument order, so `pushFront(1, 2, 3)` results in front-to-back order * `[1, 2, 3, ...existing]`. * - * @experimental **UNSTABLE**: New API, yet to be vetted. - * * @example Pushing values to the front * ```ts - * import { Deque } from "@std/data-structures/unstable-deque"; + * import { Deque } from "@std/data-structures/deque"; * import { assertEquals } from "@std/assert"; * * const deque = new Deque([4, 5]); @@ -276,11 +262,9 @@ export class Deque implements Iterable, ReadonlyDeque { /** * Remove and return the back element, or `undefined` if the deque is empty. * - * @experimental **UNSTABLE**: New API, yet to be vetted. - * * @example Popping from the back * ```ts - * import { Deque } from "@std/data-structures/unstable-deque"; + * import { Deque } from "@std/data-structures/deque"; * import { assertEquals } from "@std/assert"; * * const deque = new Deque([1, 2, 3]); @@ -303,11 +287,9 @@ export class Deque implements Iterable, ReadonlyDeque { /** * Remove and return the front element, or `undefined` if the deque is empty. * - * @experimental **UNSTABLE**: New API, yet to be vetted. - * * @example Popping from the front * ```ts - * import { Deque } from "@std/data-structures/unstable-deque"; + * import { Deque } from "@std/data-structures/deque"; * import { assertEquals } from "@std/assert"; * * const deque = new Deque([1, 2, 3]); @@ -332,11 +314,9 @@ export class Deque implements Iterable, ReadonlyDeque { * front to back. The gap is closed by shifting whichever side (front or back) * has fewer elements to move, so removals near either end are fast. * - * @experimental **UNSTABLE**: New API, yet to be vetted. - * * @example Removing the first even number * ```ts - * import { Deque } from "@std/data-structures/unstable-deque"; + * import { Deque } from "@std/data-structures/deque"; * import { assertEquals } from "@std/assert"; * * const deque = new Deque([1, 2, 3, 4]); @@ -360,11 +340,9 @@ export class Deque implements Iterable, ReadonlyDeque { * `undefined` for out-of-range indices. The gap is closed by shifting * whichever side (front or back) has fewer elements to move. * - * @experimental **UNSTABLE**: New API, yet to be vetted. - * * @example Removing by index * ```ts - * import { Deque } from "@std/data-structures/unstable-deque"; + * import { Deque } from "@std/data-structures/deque"; * import { assertEquals } from "@std/assert"; * * const deque = new Deque([10, 20, 30, 40]); @@ -374,7 +352,7 @@ export class Deque implements Iterable, ReadonlyDeque { * * @example Removing with a negative index * ```ts - * import { Deque } from "@std/data-structures/unstable-deque"; + * import { Deque } from "@std/data-structures/deque"; * import { assertEquals } from "@std/assert"; * * const deque = new Deque([10, 20, 30, 40]); @@ -395,11 +373,9 @@ export class Deque implements Iterable, ReadonlyDeque { * Return the first element matching the predicate, scanning from front to * back, without removing it. Returns `undefined` if no match is found. * - * @experimental **UNSTABLE**: New API, yet to be vetted. - * * @example Finding the first even number * ```ts - * import { Deque } from "@std/data-structures/unstable-deque"; + * import { Deque } from "@std/data-structures/deque"; * import { assertEquals } from "@std/assert"; * * const deque = new Deque([1, 2, 3, 4]); @@ -421,11 +397,9 @@ export class Deque implements Iterable, ReadonlyDeque { * Return the index of the first element matching the predicate, scanning * from front to back. Returns `-1` if no match is found. * - * @experimental **UNSTABLE**: New API, yet to be vetted. - * * @example Finding the index of the first even number * ```ts - * import { Deque } from "@std/data-structures/unstable-deque"; + * import { Deque } from "@std/data-structures/deque"; * import { assertEquals } from "@std/assert"; * * const deque = new Deque([1, 2, 3, 4]); @@ -445,11 +419,9 @@ export class Deque implements Iterable, ReadonlyDeque { * Return the front element without removing it, or `undefined` if the deque * is empty. * - * @experimental **UNSTABLE**: New API, yet to be vetted. - * * @example Peeking at the front * ```ts - * import { Deque } from "@std/data-structures/unstable-deque"; + * import { Deque } from "@std/data-structures/deque"; * import { assertEquals } from "@std/assert"; * * const deque = new Deque([1, 2, 3]); @@ -468,11 +440,9 @@ export class Deque implements Iterable, ReadonlyDeque { * Return the back element without removing it, or `undefined` if the deque * is empty. * - * @experimental **UNSTABLE**: New API, yet to be vetted. - * * @example Peeking at the back * ```ts - * import { Deque } from "@std/data-structures/unstable-deque"; + * import { Deque } from "@std/data-structures/deque"; * import { assertEquals } from "@std/assert"; * * const deque = new Deque([1, 2, 3]); @@ -492,11 +462,9 @@ export class Deque implements Iterable, ReadonlyDeque { * indices count from the back (`-1` is the last element). Returns `undefined` * for out-of-range indices. * - * @experimental **UNSTABLE**: New API, yet to be vetted. - * * @example Accessing elements by index * ```ts - * import { Deque } from "@std/data-structures/unstable-deque"; + * import { Deque } from "@std/data-structures/deque"; * import { assertEquals } from "@std/assert"; * * const deque = new Deque([10, 20, 30, 40]); @@ -519,11 +487,9 @@ export class Deque implements Iterable, ReadonlyDeque { * {@link https://tc39.es/ecma262/#sec-samevaluezero | SameValueZero} * comparison (like {@linkcode Array.prototype.includes}). * - * @experimental **UNSTABLE**: New API, yet to be vetted. - * * @example Checking for membership * ```ts - * import { Deque } from "@std/data-structures/unstable-deque"; + * import { Deque } from "@std/data-structures/deque"; * import { assertEquals } from "@std/assert"; * * const deque = new Deque([1, 2, 3]); @@ -533,7 +499,7 @@ export class Deque implements Iterable, ReadonlyDeque { * * @example NaN is found (SameValueZero semantics) * ```ts - * import { Deque } from "@std/data-structures/unstable-deque"; + * import { Deque } from "@std/data-structures/deque"; * import { assertEquals } from "@std/assert"; * * const deque = new Deque([1, NaN, 3]); @@ -555,11 +521,9 @@ export class Deque implements Iterable, ReadonlyDeque { /** * Remove all elements and release the backing buffer. * - * @experimental **UNSTABLE**: New API, yet to be vetted. - * * @example Clearing the deque * ```ts - * import { Deque } from "@std/data-structures/unstable-deque"; + * import { Deque } from "@std/data-structures/deque"; * import { assertEquals } from "@std/assert"; * * const deque = new Deque([1, 2, 3]); @@ -581,11 +545,9 @@ export class Deque implements Iterable, ReadonlyDeque { * {@linkcode Array.prototype.filter}. The predicate is called once per * element in front-to-back order. * - * @experimental **UNSTABLE**: New API, yet to be vetted. - * * @example Retaining only odd numbers * ```ts - * import { Deque } from "@std/data-structures/unstable-deque"; + * import { Deque } from "@std/data-structures/deque"; * import { assertEquals } from "@std/assert"; * * const deque = new Deque([1, 2, 3, 4, 5]); @@ -617,11 +579,9 @@ export class Deque implements Iterable, ReadonlyDeque { * Return a shallow copy of the deque's contents as an array, in * front-to-back order. * - * @experimental **UNSTABLE**: New API, yet to be vetted. - * * @example Converting to an array * ```ts - * import { Deque } from "@std/data-structures/unstable-deque"; + * import { Deque } from "@std/data-structures/deque"; * import { assertEquals } from "@std/assert"; * * const deque = new Deque([1, 2, 3]); @@ -641,11 +601,9 @@ export class Deque implements Iterable, ReadonlyDeque { /** * Create a new deque from an array-like, iterable, or existing deque. * - * @experimental **UNSTABLE**: New API, yet to be vetted. - * * @example Creating a deque from an array * ```ts - * import { Deque } from "@std/data-structures/unstable-deque"; + * import { Deque } from "@std/data-structures/deque"; * import { assertEquals } from "@std/assert"; * * const deque = Deque.from([1, 2, 3]); @@ -654,7 +612,7 @@ export class Deque implements Iterable, ReadonlyDeque { * * @example Creating a deque from an existing deque * ```ts - * import { Deque } from "@std/data-structures/unstable-deque"; + * import { Deque } from "@std/data-structures/deque"; * import { assertEquals } from "@std/assert"; * * const original = new Deque([1, 2, 3]); @@ -673,11 +631,9 @@ export class Deque implements Iterable, ReadonlyDeque { * Create a new deque from an array-like, iterable, or existing deque, with * a mapping function applied to each element. * - * @experimental **UNSTABLE**: New API, yet to be vetted. - * * @example Creating a deque with a mapping function * ```ts - * import { Deque } from "@std/data-structures/unstable-deque"; + * import { Deque } from "@std/data-structures/deque"; * import { assertEquals } from "@std/assert"; * * const deque = Deque.from([1, 2, 3], { map: (v) => v * 10 }); @@ -756,11 +712,9 @@ export class Deque implements Iterable, ReadonlyDeque { * Iterate over the deque's elements from front to back. Non-destructive * (unlike {@linkcode BinaryHeap}). * - * @experimental **UNSTABLE**: New API, yet to be vetted. - * * @example Iterating over the deque * ```ts - * import { Deque } from "@std/data-structures/unstable-deque"; + * import { Deque } from "@std/data-structures/deque"; * import { assertEquals } from "@std/assert"; * * const deque = new Deque([1, 2, 3]); @@ -778,11 +732,9 @@ export class Deque implements Iterable, ReadonlyDeque { /** * Iterate over the deque's elements from back to front. * - * @experimental **UNSTABLE**: New API, yet to be vetted. - * * @example Iterating in reverse * ```ts - * import { Deque } from "@std/data-structures/unstable-deque"; + * import { Deque } from "@std/data-structures/deque"; * import { assertEquals } from "@std/assert"; * * const deque = new Deque([1, 2, 3]); @@ -802,7 +754,7 @@ export class Deque implements Iterable, ReadonlyDeque { * * @example Usage * ```ts - * import { Deque } from "@std/data-structures/unstable-deque"; + * import { Deque } from "@std/data-structures/deque"; * import { assertEquals } from "@std/assert"; * * const deque = new Deque(); diff --git a/data_structures/unstable_deque_test.ts b/data_structures/deque_test.ts similarity index 99% rename from data_structures/unstable_deque_test.ts rename to data_structures/deque_test.ts index 34bfd8ff7299..89339e1e2755 100644 --- a/data_structures/unstable_deque_test.ts +++ b/data_structures/deque_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2026 the Deno authors. MIT license. import { assertEquals, assertStrictEquals, assertThrows } from "@std/assert"; -import { Deque, type ReadonlyDeque } from "./unstable_deque.ts"; +import { Deque, type ReadonlyDeque } from "./deque.ts"; import { MyMath } from "./_test_utils.ts"; // -- Construction -- diff --git a/data_structures/mod.ts b/data_structures/mod.ts index 4454bdd9fb48..a0527f432803 100644 --- a/data_structures/mod.ts +++ b/data_structures/mod.ts @@ -28,4 +28,5 @@ export * from "./binary_heap.ts"; export * from "./binary_search_tree.ts"; export * from "./comparators.ts"; +export * from "./deque.ts"; export * from "./red_black_tree.ts"; From a6134a0325c14e6b0ff129b9f506aa36dc6197b8 Mon Sep 17 00:00:00 2001 From: Tomas Zijdemans Date: Sun, 12 Apr 2026 12:52:51 +0200 Subject: [PATCH 2/5] fix --- import_map.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/import_map.json b/import_map.json index 7aa140dea113..ac98d585d09d 100644 --- a/import_map.json +++ b/import_map.json @@ -14,7 +14,7 @@ "@std/collections": "jsr:@std/collections@^1.1.6", "@std/crypto": "jsr:@std/crypto@^1.0.5", "@std/csv": "jsr:@std/csv@^1.0.6", - "@std/data-structures": "jsr:@std/data-structures@^1.0.10", + "@std/data-structures": "jsr:@std/data-structures@^1.1.0", "@std/datetime": "jsr:@std/datetime@^0.225.7", "@std/dotenv": "jsr:@std/dotenv@^0.225.6", "@std/encoding": "jsr:@std/encoding@^1.0.10", From d04e7aec96cda8d8b13221ceeb38d1e538a0f0f3 Mon Sep 17 00:00:00 2001 From: Tomas Zijdemans Date: Sun, 12 Apr 2026 12:54:25 +0200 Subject: [PATCH 3/5] revert --- data_structures/deno.json | 2 +- import_map.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/data_structures/deno.json b/data_structures/deno.json index 162dba4cf500..9d422b76e8aa 100644 --- a/data_structures/deno.json +++ b/data_structures/deno.json @@ -1,6 +1,6 @@ { "name": "@std/data-structures", - "version": "1.1.0", + "version": "1.0.10", "exports": { ".": "./mod.ts", "./unstable-bidirectional-map": "./unstable_bidirectional_map.ts", diff --git a/import_map.json b/import_map.json index ac98d585d09d..7aa140dea113 100644 --- a/import_map.json +++ b/import_map.json @@ -14,7 +14,7 @@ "@std/collections": "jsr:@std/collections@^1.1.6", "@std/crypto": "jsr:@std/crypto@^1.0.5", "@std/csv": "jsr:@std/csv@^1.0.6", - "@std/data-structures": "jsr:@std/data-structures@^1.1.0", + "@std/data-structures": "jsr:@std/data-structures@^1.0.10", "@std/datetime": "jsr:@std/datetime@^0.225.7", "@std/dotenv": "jsr:@std/dotenv@^0.225.6", "@std/encoding": "jsr:@std/encoding@^1.0.10", From d58f530fc0673276a5f767f5369d81d4b24c07a5 Mon Sep 17 00:00:00 2001 From: Tomas Zijdemans Date: Sun, 12 Apr 2026 12:57:12 +0200 Subject: [PATCH 4/5] fix --- data_structures/deno.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data_structures/deno.json b/data_structures/deno.json index 9d422b76e8aa..f88e662198a4 100644 --- a/data_structures/deno.json +++ b/data_structures/deno.json @@ -8,9 +8,9 @@ "./binary-search-tree": "./binary_search_tree.ts", "./unstable-binary-search-tree": "./unstable_binary_search_tree.ts", "./comparators": "./comparators.ts", + "./deque": "./deque.ts", "./red-black-tree": "./red_black_tree.ts", "./unstable-2d-array": "./unstable_2d_array.ts", - "./unstable-rolling-counter": "./unstable_rolling_counter.ts", - "./deque": "./deque.ts" + "./unstable-rolling-counter": "./unstable_rolling_counter.ts" } } From cb78fb6133423b90cb29bc94cbd6b5fd3542e96f Mon Sep 17 00:00:00 2001 From: Tomas Zijdemans Date: Sun, 12 Apr 2026 13:07:37 +0200 Subject: [PATCH 5/5] fix import --- async/unstable_channel.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/async/unstable_channel.ts b/async/unstable_channel.ts index 80120a96de0d..db495d805c2c 100644 --- a/async/unstable_channel.ts +++ b/async/unstable_channel.ts @@ -1,7 +1,7 @@ // Copyright 2018-2026 the Deno authors. MIT license. // This module is browser compatible. -import { Deque } from "../data_structures/deque.ts"; +import { Deque } from "@std/data-structures/deque"; /** Internal node for the FIFO sender waiting queue. */ interface SenderNode {