<div align="center">
<img src="https://devhub.vip/pages/docs/img/logo.png" alt="ketama-hash-ring logo" height="120">
# ketama-hash-ring
**Zero-Dependency Jump Consistent Hash, Weighted Ketama Ring & Google Maglev Lookup Tables**
[](https://crates.io/crates/ketama-hash-ring)
[](https://docs.rs/ketama-hash-ring)
[](https://github.com/crates-dev/ctares/actions/workflows/rust.yml)
[](https://www.rust-lang.org)
[](../LICENSE)
[Workspace Overview](../README.md) ยท [API Docs](https://docs.rs/ketama-hash-ring/latest/)
</div>
---
## Overview
`ketama-hash-ring` implements zero-dependency Jump Consistent Hash (`jump_consistent_hash`), weighted Ketama virtual-node rings (`ConsistentHashRing`), and compact Google Maglev O(1) lookup tables (`MaglevHash`).
## Installation
```sh
cargo add ketama-hash-ring
```
## Usage
```rust
use ketama_hash_ring::{ConsistentHashRing, MaglevHash, jump_consistent_hash};
let mut ring = ConsistentHashRing::new(64);
ring.add_node("node-a", "10.0.0.1");
ring.add_node("node-b", "10.0.0.2");
let replicas = ring.get_replicas(b"user:42", 2);
assert_eq!(replicas.len(), 2);
let maglev = MaglevHash::with_table_size(vec![("node-a", 1usize), ("node-b", 2)], 65537);
assert!(maglev.get(b"user:42").is_some());
assert!(jump_consistent_hash(42, 8) < 8);
```
## Verification
```sh
cargo run -p crate-cli -- fmt --check
cargo clippy -p ketama-hash-ring --all-features --all-targets -- -D warnings
cargo test -p ketama-hash-ring --all-features
```
## License
This project is licensed under the MIT License. See the [LICENSE](../LICENSE) file for details.
## Contact
For inquiries, please contact the author at [root@devhub.vip](mailto:root@devhub.vip).