npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@buddhilive/dsh-deque

v0.1.2-alpha.3

Published

Zero-dependency circular deque with amortized constant-time end operations and bounded vacant storage

Readme


description: "供 Host 和浏览器包使用的环形双端队列,提供摊销常数时间的队列操作、已移除条目的即时释放和有界空闲存储。" kind: "package-library"

@buddhilive/dsh-deque

English | 中文

概述

dsh-deque 让 Host 和浏览器包可以排空长期存在的进程内队列,而无需在每次移除后移动所有剩余条目。调用方可以追加或前插条目,并以摊销常数时间从前端移除。双端队列负责条目顺序和后备存储释放;唤醒、失败、取消、容量和过载行为仍由各消费方负责。

目录


使用本包

何时使用

当条目可能在异步工作期间持续积累,且消费方需要 FIFO 移除、可选前插或显式清空队列时,使用 Deque<T>。如果有限本地工作列表的最大规模使头部移除成本无关紧要,它可以继续使用数组。

入口

导入双端队列,在尾部追加条目;当条目类型可能包含 undefined 时,在移除前检查 size

import { Deque } from '@buddhilive/dsh-deque'

const frames = new Deque<string>()
frames.pushBack('first')
frames.pushFront('before-first')

while (frames.size > 0) {
  console.log(frames.popFront())
}

这些方法不施加队列限制,也不转换消费方失败。准确的 TypeScript 约定见 src/index.ts


理解实现

双端队列把条目存入环形数组。移除条目会立即清空对应槽位;按几何级数扩容并在四分之一满时缩容,使复制工作保持摊销常数时间,并防止头游标保留持续增长的空闲存储。

源码地图

| 文件 | 职责 | |---|---| | src/index.ts | 环形双端队列操作与后备存储生命周期 | | src/invariant.ts | 不变式伴生插件(无运行时不变式;顺序和存储生命周期由单元测试覆盖) | | tests/deque.spec.ts | FIFO、前插、环绕、扩容、压缩、清空和复用覆盖 | | benchmarks/drain.ts | 随队列规模增长的可复现 backlog 排空计时 |


进一步探索


模型体验

无,因为这个进程内集合不注册任何面向模型的内容。

KV 缓存影响

这里的内容不会进入模型请求,因此不影响提供方缓存复用。

已知限制与延期工作

  • 没有容量策略——双端队列不会限制、合并或拒绝条目;每个消费方必须定义适合其流的过载行为。

开发备注

无。