From f5a88c6d0abcbdd8bbeea5bbd35971b04ad64419 Mon Sep 17 00:00:00 2001 From: Will Hopkins Date: Sat, 2 Nov 2024 19:56:48 -0700 Subject: [PATCH] docs: add content to readme --- README.md | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 127 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4a373a7..1454646 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,127 @@ -# Whirlwind +# 🌀 Whirlwind -A fully asynchronous sharded hashmap for Rust. +[![Build Status](https://img.shields.io/github/actions/workflow/status/fortress-build/whirlwind/rust.yml?branch=main)](https://github.com/yourusername/shardmap/actions) +[![Crates.io](https://img.shields.io/crates/v/whirlwind)](https://crates.io/crates/whirlwind) +[![Docs.rs](https://docs.rs/whirlwind/badge.svg)](https://docs.rs/whirlwind) +[![License](https://img.shields.io/crates/l/whirlwind)](https://github.com/fortress-build/whirlwind/blob/main/LICENSE) + +An asynchronous, sharded `HashMap` for high-performance concurrent data access +in Rust. + +## 📖 Table of Contents + +- [Features](#-features) +- [Installation](#-installation) +- [Usage](#-usage) +- [Examples](#-examples) +- [Benchmark](#-benchmark) +- [Contributing](#-contributing) +- [License](#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.0" +``` + +## 🔧 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 +} +``` + +## 📊 Benchmark + +> TODO: Add benchmark figures + +## 🤝 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: + +```sh +cargo test +``` + +### Code Style + +We use `rustfmt` for code formatting: + +```sh +cargo fmt -- --check +``` ## License @@ -17,3 +138,7 @@ 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.