Thanks to visit codestin.com
Credit goes to lib.rs

#hashing #sip-hash

no-std souphash

SoupHash: an order-indipendent hash function, based on SipHash

1 unstable release

Uses new Rust 2024

0.1.0 Sep 5, 2025

#2154 in Algorithms

Codestin Search App Codestin Search App Codestin Search App

121 downloads per month

Unlicense

38KB
522 lines

SoupHash: an order-indipendent hash function

SoupHash is a non-cryptographic hash function whose output does not depend on the order of the elements that are fed into it. It is ideal for:

  • hashing of unordered collections (like hash sets and hash maps);
  • hashing large collections in parallel, using multiple threads or processes, without locks or any form of synchronization.

SoupHash is based on the popular SipHash hashing algorithm, specifically the SipHash 2-4 variant. At this moment the number of rounds used by SoupHash is not configurable (but this may change in the future).

Check the documentation for the SoupHasher struct for more details and examples.

Examples

use souphash::SoupHasher;

let mut hasher = SoupHasher::new();

// Add a few elements in arbitrary order: elements of any type are
// accepted, as long as they implement `std::hash::Hash`
hasher.add(123);
hasher.add("abc");
hasher.add([1, 2, 3]);

// Compute the final hash
let hash = hasher.finish();
assert_eq!(hash, 0xbe6f445accb8829d);

// Now repeat the same procedure as above, but this time with the elements
// in a different order: notice that the final hash does not change
let mut hasher = SoupHasher::new();
hasher.add([1, 2, 3]);
hasher.add(123);
hasher.add("abc");
let hash = hasher.finish();
assert_eq!(hash, 0xbe6f445accb8829d);

SoupHash: an order-indipendent hash function

Crate Documentation License

SoupHash is a non-cryptographic hash function whose output does not depend on the order of the elements that are fed into it. It is ideal for:

  • hashing of unordered collections (like hash sets and hash maps);
  • hashing large collections in parallel, using multiple threads or processes, without locks or any form of synchronization.

SoupHash is based on the popular SipHash hashing algorithm. This repository hosts the [Rust] implementation of SoupHash. Check the [crate documentation] to learn more!

No runtime deps