@blakeembrey/deque

中文文档
1.0.5发布于 2019/02/19Apache-2.0TypeScriptCommonJS零依赖近 30 天下载 109.3万

Deques are a generalization of stacks and queues

原始使用文档
文档目录5 节
  1. Installation
  2. Usage
  3. TypeScript
  4. Reference
  5. License

Deque

NPM version NPM downloads Build status Test coverage

Deques are a generalization of stacks and queues (the name is pronounced "deck" and is short for "double-ended queue"). -- Python collections.

Installation

npm install @blakeembrey/deque --save

Usage

  • size Returns the number of elements in the deque.
  • push(x) Add x to right side of the deque.
  • pushLeft(x) Add x to the left side of the deque.
  • clear() Remove all elements from the deque leaving it with length 0.
  • extend(iterable) Extend the right side of the deque by appending elements from iterable.
  • extendLeft(iterable) Extend the left side of the deque by appending elements from iterable.
  • peek(i) Return the element at index i in the deque.
  • indexOf(x, start?) Return the position of x in the deque.
  • has(x) Return a boolean indicating whether x is in the deque.
  • insert(i, x) Insert x into the deque at position i.
  • pop() Remove and return an element from the right side of the deque. If no elements are present, throws RangeError.
  • popLeft() Return and return an element from the left side of the deque. If no elements are present, throws RangeError.
  • delete(i) Delete the value at position i.
  • reverse() Reverse the elements of the deque in-place.
  • rotate(n=1) Rotate the deque n steps to the right.
  • entries() Return an iterable of deque.
  • @@iterator() Return an iterable of deque.
import { Deque } from '@blakeembrey/deque'

const d = new Deque('ghi')

for (const value of d) {
  console.log(value.toUpperCase()) //=> G H I
}

d.push('j')
d.pushLeft('f')
d //=> Deque(['f', 'g', 'h', 'i', 'j'])

d.pop() //=> 'j'
d.popLeft() //=> 'f'

Array.from(d) //=> ['g', 'h', 'i']

d.peek(0) //=> 'g'
d.peek(-1) //=> 'i'

d.extend('jkl')
d //=> Deque(['g', 'h', 'i', 'j', 'k', 'l'])

d.rotate(1)
d //=> Deque(['l', 'g', 'h', 'i', 'j', 'k'])

d.rotate(-1)
d //=> Deque(['g', 'h', 'i', 'j', 'k', 'l'])

const d2 = new Deque(d)

d2 //=> Deque(['g', 'h', 'i', 'j', 'k', 'l'])

TypeScript

This project uses TypeScript and publishes definitions on NPM.

Reference

Circular array implementation originally based on denque with additional optimizations.

License

Apache 2.0

版本与发布记录

@blakeembrey/deque 共发布 6 个版本,首次发布于 2018/09/10;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.5latest2019/02/197 年前
1.0.42018/11/287 年前
1.0.32018/09/128 年前
1.0.22018/09/118 年前
1.0.12018/09/118 年前
1.0.02018/09/108 年前

关于 @blakeembrey/deque 的常见问题

@blakeembrey/deque 是什么?

Deques are a generalization of stacks and queues

如何安装 @blakeembrey/deque?

在项目目录运行 npm install @blakeembrey/deque,或使用 pnpm add / yarn add / bun add。

@blakeembrey/deque 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@blakeembrey/deque 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@blakeembrey/deque 可以商用吗?

@blakeembrey/deque 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@blakeembrey/deque 的下载量有多少?

根据 npm 官方下载统计,@blakeembrey/deque 在 2026/10/09 – 2026/11/07 这 30 天内被下载 1,092,597 次,日均约 36,420 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@blakeembrey/deque 还在维护吗?

最新版本 1.0.5 发布于 2019/02/19(7 年前);至今共发布 6 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/09/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。