#lookup #consistent #hash #fallback #compatible #following #flexihash-rs

flexihash

Consistent hashing following the API and compatible with flexihash-php and flexihash-py

9 releases

0.1.8 Mar 15, 2024
0.1.7 May 6, 2020
0.1.6 Apr 13, 2020
0.1.3 Mar 31, 2020

#430 in Algorithms

Download history 2/week @ 2024-02-15 13/week @ 2024-02-22 3/week @ 2024-02-29 2/week @ 2024-03-07 113/week @ 2024-03-14 8/week @ 2024-03-21 34/week @ 2024-03-28 29/week @ 2024-04-04

74 downloads per month

MIT license

21KB
465 lines

flexihash-rs

Unit Tests

A rust port of https://github.com/pda/flexihash , aiming for 1:1 compatibility

Usage Example

use flexihash::Flexihash;

let fh = Flexihash::new();

// bulk add
fh.add_targets(vec!["cache-1", "cache-2", "cache-3"]);

// simple lookup
fh.lookup("object-a");  // "cache-1"
fh.lookup("object-b");  // "cache-2"

// add and remove
fh.add_target("cache-4");
fh.remove_target("cache-1");

// lookup with next-best fallback (for redundant writes)
fh.lookup_list("object", 2)  // ["cache-2", "cache-4"]

// remove cache-2, expect object to hash to cache-4
fh.remove_target("cache-2")
fh.lookup("object")  // "cache-4"

Dependencies

~120KB