-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This brings the code in line with my current style. It also inlines the dozen or so lines of code for FNV hashing instead of bringing in a micro-crate for it. Finally, it drops the dependency on regex in favor of using regex-syntax and regex-automata directly.
- Loading branch information
1 parent
09ff320
commit b440b99
Showing
6 changed files
with
179 additions
and
152 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/// A convenience alias for creating a hash map with an FNV hasher. | ||
pub(crate) type HashMap<K, V> = | ||
std::collections::HashMap<K, V, std::hash::BuildHasherDefault<Hasher>>; | ||
|
||
/// A hasher that implements the Fowler–Noll–Vo (FNV) hash. | ||
pub(crate) struct Hasher(u64); | ||
|
||
impl Hasher { | ||
const OFFSET_BASIS: u64 = 0xcbf29ce484222325; | ||
const PRIME: u64 = 0x100000001b3; | ||
} | ||
|
||
impl Default for Hasher { | ||
fn default() -> Hasher { | ||
Hasher(Hasher::OFFSET_BASIS) | ||
} | ||
} | ||
|
||
impl std::hash::Hasher for Hasher { | ||
fn finish(&self) -> u64 { | ||
self.0 | ||
} | ||
|
||
fn write(&mut self, bytes: &[u8]) { | ||
for &byte in bytes.iter() { | ||
self.0 = self.0 ^ u64::from(byte); | ||
self.0 = self.0.wrapping_mul(Hasher::PRIME); | ||
} | ||
} | ||
} |
Oops, something went wrong.