百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

rustc-hash

> 编程语言
开源

由 rustc 使用的自定义哈希算法(加上 hashmap 和 set 别名):速度快,确定性高,但不安全

585 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

由 rustc 使用的自定义哈希算法(加上 hashmap 和 set 别名):速度快,确定性高,但不安全

rustc-hash

A speedy, non-cryptographic hashing algorithm used by rustc. The hash map in std uses SipHash by default, which provides resistance against DOS attacks. These attacks aren't a concern in the compiler so we prefer to use a quicker, non-cryptographic hash algorithm.

The original hash algorithm provided by this crate was one taken from Firefox, hence the hasher it provides is called FxHasher. This name is kept for backwards compatibility, but the underlying hash has since been replaced. The current design for the hasher is a polynomial hash finished with a single bit rotation, together with a wyhash-inspired compression function for strings/slices, both designed by Orson Peters.

For rustc we have tried many different hashing algorithms. Hashing speed is critical, especially for single integers. Spending more CPU cycles on a higher quality hash does not reduce hash collisions enough to make the compiler faster on real-world benchmarks.

Usage

This crate provides FxHashMap and FxHashSet as collections. They are simply type aliases for their std::collection counterparts using the Fx hasher.

rust
use rustc_hash::FxHashMap;

let mut map: FxHashMap = FxHashMap::default();
map.insert(22, 44);

no_std

The std feature is on by default to enable collections. It can be turned off in Cargo.toml like so:

toml
rustc-hash = { version = "2.1", default-features = false }

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rust

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言