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

@3-/binset

v0.1.8

Published

High-performance WebAssembly binary set based on Rust HashSet (rapidhash) and Bitcode serialization / 基于 Rust HashSet (rapidhash) 与 Bitcode 序列化的高性能 WebAssembly 二进制集合

Readme

@3-/binset

English | 中文


BinSet : WebAssembly binary set based on Rust HashSet (rapidhash)

WebAssembly binary set implementation. Built with Rust HashSet (using rapidhash), serialized using Bitcode, and compiled to WebAssembly.

Table of Contents

Features

  • High-Performance Storage: Employs RapidHashSet (based on rapidhash) to achieve fast, $O(1)$ binary set operations.
  • Serialization: Uses Bitcode binary serialization for extremely compact and fast set dumping and loading.
  • WebAssembly Engine: Runs in Node.js and browser environments at native-like speeds.
  • Binary Interface: Operates directly on Uint8Array buffers without character encoding overhead.

Tech Stack

  • Core Language: Rust (2024 edition)
  • Hashing Algorithm: rapidhash (4.4.1)
  • Serialization: Bitcode (0.6.9)
  • WASM Interface: wasm-bindgen (0.2.122)
  • Optimization: wasm-opt (O3 optimization)

Directory Structure

.
├── Cargo.toml            # Rust cargo package configuration
├── build.sh              # WebAssembly compilation script
├── package.json          # npm package configuration
├── run.sh                # Test runner script
├── src
│   └── lib.rs            # Rust library implementation code
└── test.js               # JS test demo file

Design Architecture

The following diagram illustrates the call flow and component relationships:

graph TD
    JS[JS Client] -->|add / has| WASM[WASM Binding Layer]
    WASM -->|wasm-bindgen| Rust[Rust BinSet Struct]
    Rust -->|Storage Operations| HashSet[rapidhash::RapidHashSet]
    JS -->|dump / load| WASM
    WASM -->|Serialization / Deserialization| Bitcode[Bitcode Crate]
    Bitcode <-->|Binary Buffers| Rust

Usage Demo

Example written in CoffeeScript:

#!/usr/bin/env coffee

> ./pkg/_ > BinSet

s = new BinSet

# Insert binary values
s.add(
  new Uint8Array(1)
)

s.add new Uint8Array([5])

# Dump set to serialized binary, then reload
s = BinSet.load s.dump()

# Query values
console.log(
  s.has(
    new Uint8Array(1)
  )
)
console.log s.size

API Reference

BinSet Class

  • constructor(): Initializes empty BinSet.
  • add(val: Uint8Array): void: Inserts value.
  • delete(val: Uint8Array): boolean: Removes value, returns true if value was present and deleted, false otherwise.
  • clear(): void: Clears all values from set.
  • has(val: Uint8Array): boolean: Returns boolean indicating value presence.
  • values(): Iterator<Uint8Array>: Returns an iterator over the values.
  • dump(): Uint8Array: Serializes entire set into Uint8Array buffer.
  • static load(bin: Uint8Array): BinSet: Instantiates new set from serialized buffer.
  • readonly size: number: Returns total elements.

Historical Anecdote

The underlying hashing algorithm is rapidhash, the official successor to the famous wyhash non-cryptographic hash function. Wyhash was originally authored by Wang Yi. rapidhash was developed to push performance even further on modern CPUs while fully passing the rigorous SMHasher and SMHasher3 test suites for collision resistance and statistical quality.


BinSet : 基于 Rust HashSet (rapidhash) 的 WebAssembly 二进制集合

二进制集合实现。基于 Rust HashSet(使用 rapidhash 算法),配合 Bitcode 序列化,编译为 WebAssembly。

目录

功能特性

  • 高性能存储:使用 RapidHashSet(基于 rapidhash),实现快速的 $O(1)$ 二进制集合操作。
  • 序列化:使用 Bitcode 序列化协议,实现极度紧凑且快速的数据导出与导入。
  • WebAssembly 运行:支持 Node.js 及浏览器环境,运行效率高。
  • 二进制接口:直接操作 Uint8Array,避免字符编码转换开销。

技术栈

  • 核心语言:Rust (2024 edition)
  • 哈希算法:rapidhash (4.4.1)
  • 序列化库:Bitcode (0.6.9)
  • WASM 接口:wasm-bindgen (0.2.122)
  • 体积优化:wasm-opt (O3 优化)

目录结构

.
├── Cargo.toml            # Rust 项目配置
├── build.sh              # WebAssembly 编译脚本
├── package.json          # npm 包配置
├── run.sh                # 测试运行脚本
├── src
│   └── lib.rs            # Rust 库源码
└── test.js               # JS 测试演示

设计思路与架构

下图展示模块调用关系与数据流动:

graph TD
    JS[JS 客户端] -->|add / has| WASM[WASM 绑定层]
    WASM -->|wasm-bindgen| Rust[Rust BinSet 结构体]
    Rust -->|存储操作| HashSet[rapidhash::RapidHashSet]
    JS -->|dump / load| WASM
    WASM -->|序列化 / 反序列化| Bitcode[Bitcode 库]
    Bitcode <-->|二进制缓冲区| Rust

使用演示

CoffeeScript 演示代码如下:

#!/usr/bin/env coffee

> ./pkg/_ > BinSet

s = new BinSet

# 插入二进制值
s.add(
  new Uint8Array(1)
)

s.add new Uint8Array([5])

# 序列化导出并重新加载
s = BinSet.load s.dump()

# 查询值
console.log(
  s.has(
    new Uint8Array(1)
  )
)
console.log s.size

API 说明

BinSet

  • constructor():初始化空集合。
  • add(val: Uint8Array): void:插入值。
  • delete(val: Uint8Array): boolean:删除值,若存在且删除成功返回 true,否则返回 false
  • clear(): void:清空集合。
  • has(val: Uint8Array): boolean:判断值是否存在。
  • values(): Iterator<Uint8Array>:获取包含所有值的迭代器。
  • dump(): Uint8Array:将集合序列化为 Uint8Array 缓冲区。
  • static load(bin: Uint8Array): BinSet:从二进制缓冲区反序列化并构建 BinSet。
  • readonly size: number:返回集合内元素总数。

历史小故事

底层哈希算法 rapidhash 是著名的非加密哈希算法 wyhash 的官方继承者。wyhash 最初由王一(Wang Yi)设计。rapidhash 的开发旨在进一步提升在现代 CPU 上的性能表现,同时完全通过了严格的 SMHasher 和 SMHasher3 哈希碰撞与质量测试套件。


About

This project is an open-source component of i18n.site ⋅ Internationalization Solution.

关于

本项目为 i18n.site ⋅ 国际化解决方案 的开源组件。