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-/binmap

v0.1.22

Published

High-performance WebAssembly binary map based on Rust BTreeMap and Speedy serialization / 基于 Rust BTreeMap 与 Speedy 序列化的高性能 WebAssembly 二进制键值映射表

Downloads

1,251

Readme

@3-/binmap

English | 中文


BinMap : WebAssembly binary key-value map based on Rust RapidHashMap

WebAssembly binary key-value map implementation. Built with Rust RapidHashMap, serialized using Bitcode, and compiled to WebAssembly.

Table of Contents

Features

  • High Performance Storage: Employs rapidhash for fast in-memory key-value lookups.
  • Serialization: Uses Bitcode binary serialization for extremely fast and compact map 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: Rapidhash (1.4)
  • Serialization: Bitcode (0.6)
  • 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] -->|set / get / has| WASM[WASM Binding Layer]
    WASM -->|wasm-bindgen| Rust[Rust BinMap Struct]
    Rust -->|Storage Operations| RapidHashMap[rapidhash::RapidHashMap]
    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/_ > BinMap

m = new BinMap

# Insert binary keys and values
m.set(
  new Uint8Array(1)
  new Uint8Array([1,2,3])
)

m.set new Uint8Array([5]), new Uint8Array [5,6]

# Dump map to serialized binary, then reload
m = BinMap.load m.dump()

# Query keys
console.log(
  m.get(
    new Uint8Array(1)
  )
)
console.log m.size

API Reference

BinMap Class

  • constructor(): Initializes empty BinMap.
  • set(key: Uint8Array, val: Uint8Array): void: Inserts or updates key-value pair.
  • delete(key: Uint8Array): boolean: Removes key-value pair, returns true if key was present and deleted, false otherwise.
  • clear(): void: Clears all key-value pairs from map.
  • get(key: Uint8Array): Uint8Array | undefined: Returns value associated with key, or undefined if not found.
  • has(key: Uint8Array): boolean: Returns boolean indicating key presence.
  • keys(): Iterator<Uint8Array>: Returns an iterator over the keys.
  • values(): Iterator<Uint8Array>: Returns an iterator over the values.
  • entries(): Iterator<[Uint8Array, Uint8Array]>: Returns an iterator over the key-value pairs.
  • dump(): Uint8Array: Serializes entire map into Uint8Array buffer.
  • static load(bin: Uint8Array): BinMap: Instantiates new map from serialized buffer.
  • readonly size: number: Returns total key-value pairs.

Historical Anecdote

The underlying core data structure is based on rapidhash, which is the official successor to wyhash. wyhash and rapidhash are among the fastest quality-assured non-cryptographic hash functions, consistently passing SMHasher and SMHasher3 benchmarks. The name rapidhash is derived from its main goal: delivering exceptional execution speeds across diverse platforms.


BinMap : 基于 Rust RapidHashMap 的 WebAssembly 二进制键值映射表

二进制键值映射表实现。基于 Rust RapidHashMap,配合 Bitcode 序列化,编译为 WebAssembly。

目录

功能特性

  • 高性能存储:使用 rapidhash,提供极快内存键值检索。
  • 序列化:使用 Bitcode 二进制序列化,加速数据导出与导入,且生成的数据极度紧凑。
  • WebAssembly 运行:支持 Node.js 及浏览器环境,运行效率高。
  • 二进制接口:直接操作 Uint8Array,避免字符编码转换开销。

技术栈

  • 核心语言:Rust (2024 edition)
  • 哈希算法:Rapidhash (1.4)
  • 序列化库:Bitcode (0.6)
  • 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 客户端] -->|set / get / has| WASM[WASM 绑定层]
    WASM -->|wasm-bindgen| Rust[Rust BinMap 结构体]
    Rust -->|存储操作| RapidHashMap[rapidhash::RapidHashMap]
    JS -->|dump / load| WASM
    WASM -->|序列化 / 反序列化| Bitcode[Bitcode 库]
    Bitcode <-->|二进制缓冲区| Rust

使用演示

CoffeeScript 演示代码如下:

#!/usr/bin/env coffee

> ./pkg/_ > BinMap

m = new BinMap

# 插入键值对
m.set(
  new Uint8Array(1)
  new Uint8Array([1,2,3])
)

m.set new Uint8Array([5]), new Uint8Array [5,6]

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

# 查询键值
console.log(
  m.get(
    new Uint8Array(1)
  )
)
console.log m.size

API 说明

BinMap

  • constructor():初始化空映射表。
  • set(key: Uint8Array, val: Uint8Array): void:插入或更新键值对。
  • delete(key: Uint8Array): boolean:删除键值对,若键存在且删除成功返回 true,否则返回 false
  • clear(): void:清空映射表。
  • get(key: Uint8Array): Uint8Array | undefined:获取键对应值,未找到返回 undefined
  • has(key: Uint8Array): boolean:判断键是否存在。
  • keys(): Iterator<Uint8Array>:获取包含所有键的迭代器。
  • values(): Iterator<Uint8Array>:获取包含所有值的迭代器。
  • entries(): Iterator<[Uint8Array, Uint8Array]>:获取包含所有键值对的迭代器。
  • dump(): Uint8Array:将映射表序列化为 Uint8Array 缓冲区。
  • static load(bin: Uint8Array): BinMap:从二进制缓冲区反序列化并构建 BinMap。
  • readonly size: number:返回键值对总数。

历史小故事

映射表核心数据结构基于 rapidhashrapidhash 是目前最快的非加密哈希算法之一 wyhash 的官方继承者,在 SMHasher 和 SMHasher3 基准测试中表现优异,全部测试均顺利通过。它的名字 rapidhash 来源于其主要设计目标:在各种主流硬件平台上提供极致的执行速度。


About

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

关于

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