-
Notifications
You must be signed in to change notification settings - Fork 516
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Uses a hashset to de-duplicate results
This creates a `HashSet<u64>` using FNV Hashing, because it's much faster than Rust's default SIP hash and this isn't used for anything that needs to be cyptographically secure. It also allows us to keep a hashset of 64bit numbers, instead of Strings or string slices thus reducing memory consumption. In unscientific benchmarks of ~5,200 `.cheat` lines containing about `2,600` duplicate lines there was no noticable increase in memory consumption (benchmarking time is harder since you wait for human input), both master (HEAD b78903a) and this commit used 10.8mb max RSS. To attempt to measure time (and again max RSS) running master against this commit using the command `navi --print --path dups_folder/ best "git tag"` resulted in a *decrease* of memory consumption by about 200k, and no noticable time increase. Closes #283
- Loading branch information
Showing
3 changed files
with
55 additions
and
4 deletions.
There are no files selected for viewing
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,42 @@ | ||
use std::hash::{Hash, Hasher}; | ||
|
||
const MAGIC_INIT: u64 = 0x811C_9DC5; | ||
|
||
pub trait HashLine: Hash { | ||
fn hash_line(&self) -> u64; | ||
} | ||
|
||
impl<T> HashLine for T | ||
where | ||
T: Hash, | ||
{ | ||
fn hash_line(&self) -> u64 { | ||
let mut hasher = FnvHasher::new(); | ||
self.hash(&mut hasher); | ||
hasher.finish() | ||
} | ||
} | ||
|
||
pub(crate) struct FnvHasher(u64); | ||
|
||
impl FnvHasher { | ||
pub(crate) fn new() -> Self { | ||
FnvHasher(MAGIC_INIT) | ||
} | ||
} | ||
|
||
impl Hasher for FnvHasher { | ||
fn finish(&self) -> u64 { | ||
self.0 | ||
} | ||
fn write(&mut self, bytes: &[u8]) { | ||
let FnvHasher(mut hash) = *self; | ||
|
||
for byte in bytes.iter() { | ||
hash ^= u64::from(*byte); | ||
hash = hash.wrapping_mul(0x0100_0000_01b3); | ||
} | ||
|
||
*self = FnvHasher(hash); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ mod cheat; | |
mod cmds; | ||
mod display; | ||
mod filesystem; | ||
mod fnv; | ||
mod fzf; | ||
mod git; | ||
mod handler; | ||
|