linkspace/commons/dedup.rs
1use linkspace_core::point::{B64, LkHash};
2
3/// return true if already seen
4pub fn lkc_dedup_seen(capacity: usize) -> impl FnMut(&LkHash) -> bool {
5 let mut bufs = vec![B64([0; 32]); capacity].into_boxed_slice();
6 move |hash: &LkHash| {
7 let i: usize = usize::from_ne_bytes(*hash.0.rsplit_array_ref().1);
8 let idx = i % bufs.len();
9 let seen = &bufs[idx] == hash;
10 bufs[idx] = *hash;
11 seen
12 }
13}