3 unstable releases

0.2.1 May 23, 2021
0.2.0 Apr 14, 2021
0.1.1 Apr 14, 2021
0.1.0 Feb 19, 2021

#2413 in Algorithms

Download history 983/week @ 2024-07-25 1033/week @ 2024-08-01 811/week @ 2024-08-08 996/week @ 2024-08-15 964/week @ 2024-08-22 763/week @ 2024-08-29 703/week @ 2024-09-05 714/week @ 2024-09-12 754/week @ 2024-09-19 1218/week @ 2024-09-26 1254/week @ 2024-10-03 1183/week @ 2024-10-10 1216/week @ 2024-10-17 773/week @ 2024-10-24 444/week @ 2024-10-31 376/week @ 2024-11-07

3,034 downloads per month
Used in 2 crates (via minimizer-queue)

MIT/Apache

10KB
225 lines

WyHash2

A simple, light and fast hashing algorithm written by Wang Yi. Ported to rust for your ease of use.

Thanks also goes to Eldruin their WyHash was very helpful for reference on getting started.

Features

  • nightly which enables some nightly only intrinsicts which can help improve performance.

  • std This is enabled by default, however can be disabled for no_std enviroments

Usage

A basic example:

use core::hash::Hasher;
use wyhash2::WyHash;

fn main() {
    let secret = 0;
    let mut hasher = WyHash::with_seed(secret);
    hasher.write(&[0, 1, 2]);
    println!("We got {}", hasher.finish());
}

Wyhash2 Implements BuildHasher which means it can be used as the hasher for the Hashmap

Usage with a Hashmap:

use wyhash2::WyHash;
use std::collections::HashMap;

fn main() {
    let hasher = WyHash::with_seed(0);
    let mut map: HashMap<String, String, WyHash> = HashMap::with_hasher(hasher);

    map.insert("Hello".to_string(), "World".to_string());

    println!("We got {}", map.get("Hello").unwrap());
}

no_std usage

[dependencies]
wyhash2 = { version = "...", default-features = false }

License

Licensed under either of

at your option.

Dependencies

~22KB