Denque-on-Greasy-Fork

(https://github.com/Salakar) Fast, well-tested double-ended queue implementation based on ring buffer

Ekde 2025/12/27. Vidu La ĝisdata versio.

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://updategf.qytechs.cn/scripts/559642/1722290/Denque-on-Greasy-Fork.js

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

Aŭtoro
JasonMel
Versio
2.1.0h
Kreita
2025/12/20
Ĝisdatigita
2025/12/27
Size
29,8 kb
Licenco
Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)

This is Mike Diarmid's Denque class. https://github.com/Salakar — copyright (c) 2018 Invertase Limited https://github.com/invertase/denque

Repackaged here for userscripts, instead of the original packaging as a CommonJS module for Node.js.

From the Github homepage at https://github.com/invertase/denque:

Denque is a well tested, extremely fast and lightweight double-ended queue implementation with zero dependencies and includes TypeScript types.

This implementation is currently the fastest available, even faster than double-ended-queue, see the benchmarks.

Every queue operation is done at a constant O(1) - including random access from .peekAt(index).


To use: Inside an async function,

const Deque = await importDenque();
const myDoubleEndedQueue = new Deque();

The instance returned by new will have all the usual methods of a deque (pronounced "deck" like a deck of cards): push, pop, unshift, shift, isEmpty, and so on. See the Denque code for documentation.

Additionally, any script using this library must include the following metadata:

// @grant       GM_getResourceText
// @grant       GM.getResourceText
// @resource    DENQUE https://cdn.jsdelivr.net/npm/[email protected]/index.js
// @require     https://update.greasyfork.org/scripts/559642/<latest>/Denque-on-Greasy-Fork.js

(You must manually obtain the @require URLs of the latest dependency versions on their respective pages, since script managers apparently only update scripts, not @requires.)

This is necessary because this library @requires a subordinate library with its own dependency, and

  1. Scripts must @require all dependencies recursively (i.e., its dependencies, its dependencies' dependencies, its dependencies' dependencies' dependencies, etc).
  2. Scripts must include all @grants needed by each dependency, recursively.

So don't make the mistake that I made, and think that putting what each library needs in its own metadata is enough. It's not!