(https://github.com/Salakar) Fast, well-tested double-ended queue implementation based on ring buffer
Ekde
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
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
@require all dependencies recursively (i.e., its dependencies, its dependencies' dependencies, its dependencies' dependencies' dependencies, etc).@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!