ddc contain

dedup
Avril 4 years ago
parent 9a7234806f
commit 6aa033ebbb
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -1,9 +1,55 @@
//! Container for chain
use super::*;
use chain::{Chain, Chainable};
use dedup::HashRefSet;
#[derive(Debug, Serialize, Deserialize)]
pub struct ChainContainer<T: Chainable>
{
chain: Chain<T>,
inputs_exact: dedup::HashRefSet<[T]>,
inputs_exact: HashRefSet<[T]>,
}
impl<T: Chainable> ChainContainer<T>
{
pub fn new() -> Self
{
Self {
chain: Chain::new(),
inputs_exact: HashRefSet::new(),
}
}
pub fn force_feed<U: AsRef<[T]>>(&mut self, tokens: U)
{
self.inputs_exact.insert(&tokens.as_ref());
self.chain.feed(tokens);
}
pub fn feed<U: AsRef<[T]>>(&mut self, tokens: U) -> bool
{
let tokens=tokens.as_ref();
if self.inputs_exact.insert(&tokens) {
self.chain.feed(tokens);
true
} else {
trace!("Exact duplication input disallowed");
false
}
}
pub fn chain(&self) -> &Chain<T>
{
&self.chain
}
}
impl<T: Chainable> From<Chain<T>> for ChainContainer<T>
{
fn from(chain: Chain<T>) -> Self
{
Self {
chain,
inputs_exact: HashRefSet::new(),
}
}
}

@ -9,7 +9,7 @@ use std::{
use sha2::{Sha256, Digest};
use cryptohelpers::sha256::Sha256Hash;
fn compute<T: Hash>(thing: &T) -> Sha256Hash
fn compute<T: Hash + ?Sized>(thing: &T) -> Sha256Hash
{
use std::mem::size_of;
struct Sha256Hasher(Sha256);
@ -65,7 +65,7 @@ impl<T: Hash + ?Sized> util::NewCapacity for HashRefSet<T>
}
}
impl<T: Hash> HashRefSet<T>
impl<T: Hash + ?Sized> HashRefSet<T>
{
pub fn insert<U>(&mut self, value: &U) -> bool
where U: Borrow<T>

@ -245,7 +245,7 @@ pub async fn host(from: ChainHandle<String>)
trace!("Begin polling on child");
tokio::select!{
v = &mut child => {
match v {
match v {
#[cold] Ok(_) => {warn!("Child exited before we have? This should probably never happen.")},//Should never happen.
Err(e) => {error!("Child exited abnormally. Aborting: {}", e)}, //Child panic or cancel.
}

Loading…
Cancel
Save