Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
๐ฆ FVN64-RS
A lightweight, zero-dependency, no_std implementation of the 64-bit FowlerโNollโVo (FNV) non-cryptographic hash
function in Rust.
This crate provides high-performance implementations of the FNV-0, FNV-1, and FNV-1a algorithms using const generics to ensure zero-cost abstractions.
๐ก Why FNV?
FNV is a non-cryptographic hash function created by Glenn Fowler, Landon Curt Noll, and Kiem-Phong Vo. It is designed to be:
- Extremely fast to compute.
- Easy to implement (only multiplication and XOR).
- Low collision rate for common data types.
It is particularly effective for small data sets like property names in compilers, object keys in scripts, or small strings.
๐ Features
- Zero Dependencies: Pure Rust implementation with no external requirements.
no_stdSupport: Ideal for embedded systems and low-level kernel development.- Const Generics: Uses modern Rust features to provide a generic interface for FNV variants.
- Standard Library Integration: Fully implements
core::hash::Hasherandcore::hash::BuildHasher.
๐ฆ Usage
Add this to your Cargo.toml:
[]
= "0.1.0"
๐ ๏ธ Using with HashMap
The FNV algorithm is frequently used in hash maps because of its speed and low collision rate for short keys (like strings or integers).
use HashMap;
use FvnBuildHasher;
// Initialize a HashMap using the FNV-1a BuildHasher
let mut map: = default;
map.insert;
map.insert;
assert_eq!;
assert_eq!;
assert_eq!;
๐ ๏ธ Using with HashSet
The FNV algorithm is frequently used in hash sets because of its speed and low collision rate for short keys (like strings or integers).
use HashMap;
use FvnBuildHasher;
// Initialize a HashSet using the FNV-1a BuildHasher
let mut set: = default;
set.insert;
set.insert;
assert!;
assert!;
assert!;
๐ ๏ธ Direct Hashing
You can use the hasher directly to compute values for specific data:
use Hasher;
use Fvn1aHasher;
let mut hasher = default;
hasher.write;
let result = hasher.finish;
println!;
๐ฆ Collections (Standard Library)
When the std feature is enabled, fnv64-rs provides convenient type aliases for standard library collections. These are pre-configured with FNV hashers and re-exported at the crate root for a seamless developer experience.
Available Aliases
| Type | Hash Algorithm | Collection |
|---|---|---|
FvnHashMap<K, V> |
FNV-1a (Default) | HashMap |
FvnHashSet<V> |
FNV-1a (Default) | HashSet |
Fvn1aHashMap<K, V> |
FNV-1a | HashMap |
Fvn1aHashSet<V> |
FNV-1a | HashSet |
Fvn1HashMap<K, V> |
FNV-1 | HashMap |
Fvn1HashSet<V> |
FNV-1 | HashSet |
Fvn0HashMap<K, V> |
FNV-0 | HashMap |
Fvn0HashSet<V> |
FNV-0 | HashSet |
[!TIP] On Nightly Rust, these aliases also support the Allocator API, allowing you to use FNV collections with custom memory allocators. Use
--features nightlyto enable this.
๐ ๏ธ Example: Drop-in Replacement
You can use these aliases directly without needing to manually import or configure a BuildHasher:
use ;
// No complex generic boilerplate needed!
let mut map = default;
map.insert;
let mut set = default;
set.insert;
๐ Algorithm Variants
| Variant | Implementation | Logic | Characteristics |
|---|---|---|---|
| FNV-1a | fvn64_rs::Fvn1aHasher |
(hash ^ byte) * PRIME |
Recommended. Best avalanche characteristics. |
| FNV-1 | fvn64_rs::Fvn1Hasher |
(hash * PRIME) ^ byte |
The original FNV-1 specification. |
| FNV-0 | fvn64_rs::Fvn0Hasher |
hash = 0; ... |
Deprecated. Included for historical purposes. |
| DEFAULT | fvn64_rs::FvnHasher |
(hash ^ byte) * PRIME |
Default implementation. Implements FNV-1a. |
โ๏ธ License
This project is licensed under the Apache-2.0 License.