parent
2155e729d7
commit
a1c9f4cd39
@ -0,0 +1,36 @@
|
||||
use super::*;
|
||||
use std::hash::{BuildHasherDefault, Hasher};
|
||||
use smallvec::SmallVec;
|
||||
use cryptohelpers::sha256;
|
||||
|
||||
/// A hasher that takes the first 8 bytes from SHA256 hash as its output.
|
||||
///
|
||||
/// # Notes
|
||||
/// Intended for use for `HashSet` with a SHA256 key.
|
||||
/// Hashing anything other than a SHA256 hash with this hasher is undefined.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd, Default)]
|
||||
pub struct Sha256TopHasher(SmallVec<[u8; sha256::SIZE]>);
|
||||
|
||||
/// A `BuildHasher` for [`Sha256TopHasher`].
|
||||
pub type Sha256TopBuildHasher = BuildHasherDefault<Sha256TopHasher>;
|
||||
|
||||
impl Sha256TopHasher
|
||||
{
|
||||
/// Create a new hasher
|
||||
#[inline] fn new() -> Self
|
||||
{
|
||||
Self(SmallVec::new())
|
||||
}
|
||||
}
|
||||
|
||||
impl Hasher for Sha256TopHasher
|
||||
{
|
||||
#[inline] fn finish(&self) -> u64 {
|
||||
let mut bytes = [0u8; std::mem::size_of::<u64>()];
|
||||
crate::slice::copy_bytes(self.0.as_ref(), &mut bytes[..]);
|
||||
u64::from_le_bytes(bytes)
|
||||
}
|
||||
#[inline] fn write(&mut self, bytes: &[u8]) {
|
||||
self.0.extend_from_slice(bytes);
|
||||
}
|
||||
}
|
@ -1,16 +1,10 @@
|
||||
use std::iter::FusedIterator;
|
||||
use std::collections::BTreeSet;
|
||||
use std::borrow::Borrow;
|
||||
use futures::prelude::*;
|
||||
use super::*;
|
||||
|
||||
/// An iterator that may be empty.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct MaybeIter<I, T>(Option<I>)
|
||||
where I: Iterator<Item=T>;
|
||||
|
||||
mod streams;
|
||||
pub use streams::*;
|
||||
|
||||
pub trait OptionIterExt<I, T>: Sized
|
||||
where I: Iterator<Item=T>
|
||||
{
|
@ -0,0 +1,13 @@
|
||||
use std::iter::FusedIterator;
|
||||
use std::collections::BTreeSet;
|
||||
use std::borrow::Borrow;
|
||||
use futures::prelude::*;
|
||||
|
||||
mod iters;
|
||||
pub use iters::*;
|
||||
|
||||
mod streams;
|
||||
pub use streams::*;
|
||||
|
||||
mod hashers;
|
||||
pub use hashers::*;
|
Loading…
Reference in new issue