Crates.io | whirlwind |
lib.rs | whirlwind |
version | 0.1.1 |
source | src |
created_at | 2024-11-02 01:34:30.320617 |
updated_at | 2024-11-04 09:00:58.275849 |
description | Collection of thread-safe, asynchronous data structures. |
homepage | |
repository | https://github.com/fortress-build/whirlwind |
max_upload_size | |
id | 1432556 |
size | 274,608 |
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.
async
/await
syntax.HashMap
-like interface for ease of adoption.Add whirlwind
to your Cargo.toml
:
[dependencies]
whirlwind = "0.1.1"
Here's a quick example to get you started:
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;
}
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);
}
use whirlwind::ShardMap;
#[tokio::main]
async fn main() {
let map = ShardMap::with_shards(64); // Initialize with 64 shards
// Use the map as needed
}
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.
Contributions are welcome! Please follow these steps:
git checkout -b feature/your-feature
.git commit -am 'Add your feature'
.git push origin feature/your-feature
.Ensure all tests pass before submitting a PR:
cargo test
We use rustfmt
for code formatting:
cargo fmt -- --check
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
http://www.apache.org/licenses/LICENSE-2.0
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.