1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
//! [](https://github.com/dante19031999/fnv-rs/tree/main?tab=Apache-2.0-1-ov-file#readme)
//! [](#)
//! [](https://blog.rust-lang.org/2021/10/21/Rust-1.56.0.html)
//! [](https://crates.io/crates/fnv64-rs)
//! [](https://docs.rs/fnv64-rs)
//!
//! # FNV Hashing
//!
//! An implementation of the [Fowler–Noll–Vo (FNV)](https://en.wikipedia.org/wiki/Fowler–Noll–Vo_hash_function)
//! non-cryptographic hash function.
//!
//! This crate provides the 64-bit versions of FNV-0, FNV-1, and FNV-1a.
//! FNV hashes are designed to be fast while maintaining a low collision rate,
//! making them ideal for use in lookup tables and hash maps.
//!
//! # 🦀 FNV64-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:
//!
//! 1. Extremely fast to compute.
//! 2. Easy to implement (only multiplication and XOR).
//! 3. 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_std` Support**: 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::Hasher` and `core::hash::BuildHasher`.
//!
//! ## 📦 Usage
//!
//! Add this to your `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! fnv64-rs = "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).
//!
//! ```rust
//! use std::collections::HashMap;
//! use fnv64_rs::FnvBuildHasher;
//!
//! // Initialize a HashSet using the FNV-1a BuildHasher
//! let mut map: HashMap<String, i32, FnvBuildHasher> = HashMap::default();
//!
//! map.insert("apple".to_string(), 1);
//! map.insert("orange".to_string(), 2);
//!
//! assert_eq!(map.get("apple"), Some(&1));
//! assert_eq!(map.get("orange"), Some(&2));
//! assert_eq!(map.get("pineapple"), None);
//! ```
//!
//! ## 🛠️ 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).
//!
//! ```rust
//! use std::collections::HashSet;
//! use fnv64_rs::FnvBuildHasher;
//!
//! // Initialize a HashMap using the FNV-1a BuildHasher
//! let mut set: HashSet<String, FnvBuildHasher> = HashSet::default();
//!
//! set.insert("apple".to_string());
//! set.insert("orange".to_string());
//!
//! assert!(set.contains("apple"));
//! assert!(set.contains("orange"));
//! assert!(!set.contains("pineapple"));
//! ```
//!
//! ## 🛠️ Direct Hashing
//!
//! You can use the hasher directly to compute values for specific data:
//!
//! ```rust
//! use core::hash::Hasher;
//! use fnv64_rs::Fnv1aHasher;
//!
//! let mut hasher = Fnv1aHasher::default();
//! hasher.write(b"hello world");
//! let result = hasher.finish();
//!
//! println!("Hash: {:x}", result);
//! ```
//!
//! ## 📦 Collections (Standard Library)
//!
//! [](https://doc.rust-lang.org/std/)
//!
//! 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 |
//! |:---------------------|:---------------------|:-----------|
//! | [`FnvHashMap<K, V>`] | **FNV-1a** (Default) | [`HashMap`][std::collections::HashMap] |
//! | [`FnvHashSet<V>`] | **FNV-1a** (Default) | [`HashSet`][std::collections::HashSet] |
//! | [`Fnv1aHashMap<K, V>`] | **FNV-1a** | [`HashMap`][std::collections::HashMap] |
//! | [`Fnv1aHashSet<V>`] | **FNV-1a** | [`HashSet`][std::collections::HashSet] |
//! | [`Fnv1HashMap<K, V>`] | **FNV-1** | [`HashMap`][std::collections::HashMap] |
//! | [`Fnv1HashSet<V>`] | **FNV-1** | [`HashSet`][std::collections::HashSet] |
//! | [`Fnv0HashMap<K, V>`] | **FNV-0** | [`HashMap`][std::collections::HashMap] |
//! | [`Fnv0HashSet<V>`] | **FNV-0** | [`HashSet`][std::collections::HashSet] |
//!
//! > [!TIP]
//! > On **Nightly Rust**, these aliases also support the **Allocator API**, allowing you to use FNV collections with custom
//! > memory allocators. Use `--features nightly` to enable this.
//!
//! ### 🛠️ Example: Drop-in Replacement
//!
//! You can use these aliases directly without needing to manually import or configure a BuildHasher:
//!
//! ```rust
//! # #[cfg(feature = "std")]
//! # {
//! use fnv64_rs::{FnvHashMap, FnvHashSet};
//!
//! // No complex generic boilerplate needed!
//! let mut map = FnvHashMap::default();
//! map.insert("id_01", 100);
//!
//! let mut set = FnvHashSet::default();
//! set.insert("admin");
//! # }
//! ```
//!
//! ## 📊 Algorithm Variants
//!
//! | Variant | Implementation | Logic | Characteristics |
//! |:------------|:------------------------|:------------------------|:---------------------------------------------------|
//! | **FNV-1a** | `fnv64_rs::Fnv1aHasher` | `(hash ^ byte) * PRIME` | **Recommended.** Best avalanche characteristics. |
//! | **FNV-1** | `fnv64_rs::Fnv1Hasher` | `(hash * PRIME) ^ byte` | The original FNV-1 specification. |
//! | **FNV-0** | `fnv64_rs::Fnv0Hasher` | `hash = 0; ...` | Deprecated. Included for historical purposes. |
//! | **DEFAULT** | `fnv64_rs::FnvHasher` | `(hash ^ byte) * PRIME` | **Default** implementation. Implements **FNV-1a**. |
//!
//! ## ⚖️ License
//!
//! This project is licensed under
//! the [Apache-2.0 License](https://github.com/dante19031999/fnv-rs/tree/main?tab=Apache-2.0-1-ov-file#readme).
pub use *;
pub use *;
pub use *;
pub use *;
pub use FnvHashMap;
pub use FnvHashSet;
/// An alias for the default 64-bit FNV hasher.
///
/// This currently points to [`Fnv1aHasher`], which is the recommended
/// variant for most applications due to its superior bit-dispersion properties.
pub use Fnv1aHasher as FnvHasher;
/// An alias for the default 64-bit FNV build hasher.
///
/// This provides a convenient way to use FNV with standard library collections:
///
/// ```rust
/// use std::collections::HashMap;
/// use fnv64_rs::FnvBuildHasher;
///
/// let mut map: HashMap<String, i32, FnvBuildHasher> = HashMap::default();
/// map.insert("apple".to_string(), 1);
/// ```
pub use Fnv1aBuildHasher as FnvBuildHasher;