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

whirlwind

> 编程语言
开源

用于 Rust 的异步分片哈希映射

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

工具介绍

用于 Rust 的异步分片哈希映射

Whirlwind

An asynchronous, sharded HashMap for high-performance concurrent data access in Rust.

[!NOTE] This crate is in development, and breaking changes may be made up until a 1.0 release.

Table of Contents

  • Features
  • Installation
  • Usage
  • Examples
  • Benchmark
  • Contributing
  • License

✨ Features

  • Async Ready: Seamless integration with Rust's async/await syntax.
  • High Performance: Sharding minimizes lock contention in concurrent environments.
  • Thread-safe: Safe for use across multiple threads without fear of data races.
  • Familiar API: Intuitive HashMap-like interface for ease of adoption.
  • Customizable Shards: Configure the number of shards to optimize for your workload.

Installation

Add whirlwind to your Cargo.toml:

toml
[dependencies]
whirlwind = "0.1.1"

Usage

Here's a quick example to get you started:

rust
use whirlwind::ShardMap;

#[tokio::main]
async fn main() {
    let map = ShardMap::new();

    map.insert("apple", 3).await;
    map.insert("banana", 5).await;

    if let Some(quantity) = map.get(&"apple").await {
        println!("We have {} apples!", quantity);
    }

    map.remove(&"banana").await;
}

Examples

Concurrent Inserts

rust
use whirlwind::ShardMap;
use tokio::task::JoinSet;

#[tokio::main]
async fn main() {
    let map = ShardMap::new();
    let tasks: JoinSet = (0..1000).map(|i| {
        let map = map.clone();
        tokio::spawn(async move {
            map.insert(i, i * 2).await;
        })
    }).collect();

    tasks.join_all().await.ok();

    assert_eq!(map.len().await, 1000);
}

Custom Shard Count

rust
use whirlwind::ShardMap;

#[tokio::main]
async fn main() {
    let map = ShardMap::with_shards(64); // Initialize with 64 shards
    // Use the map as needed
}

Benchmarks

Benchmarks were run in a asyncified version of this benchmark. You can find it here. Since the benchmarks use jonhoo/bustle, an asyncified fork of that library (here) is required.

Machine: Apple M3 Max (2023 16-inch MacBook Pro, 36GB RAM)

OS: macOS 15.0

See the results/ directory.

Read Heavy (std hasher)

Exchange (std hasher)

Rapid Grow (std hasher)

Read Heavy (ahash)

Exchange (ahash)

Rapid Grow (ahash)

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository.
  2. Create a new branch: git checkout -b feature/your-feature.
  3. Commit your changes: git commit -am 'Add your feature'.
  4. Push to the branch: git push origin feature/your-feature.
  5. Open a pull request.

Running Tests

Ensure all tests pass before submitting a PR:

bash
cargo test

Code Style

We use rustfmt for code formatting:

bash
cargo fmt -- --check

License

Copyright 2024 Will Hopkins

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


Made with and Rust.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

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

> 标签

Rustasyncasync-rustconcurrencyconcurrent-hashmap

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

> 工具信息

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

> 相关工具

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