diff --git a/examples/spines.rs b/examples/spines.rs index 4ae540e5d..b0f5eddd1 100644 --- a/examples/spines.rs +++ b/examples/spines.rs @@ -41,13 +41,13 @@ fn main() { keys.join_core(&data, |_k, &(), &()| Option::<()>::None) .probe_with(&mut probe); }, - // "rhh" => { - // use differential_dataflow::trace::implementations::rhh::{HashWrapper, VecSpine}; - // let data = data.map(|x| HashWrapper { inner: x }).arrange::>(); - // let keys = keys.map(|x| HashWrapper { inner: x }).arrange::>(); - // keys.join_core(&data, |_k, &(), &()| Option::<()>::None) - // .probe_with(&mut probe); - // }, + "rhh" => { + use differential_dataflow::trace::implementations::rhh::{HashWrapper, VecSpine}; + let data = data.map(|x| HashWrapper { inner: x }).arrange::>(); + let keys = keys.map(|x| HashWrapper { inner: x }).arrange::>(); + keys.join_core(&data, |_k, &(), &()| Option::<()>::None) + .probe_with(&mut probe); + }, "slc" => { use differential_dataflow::trace::implementations::ord_neu::PreferredSpine; @@ -61,10 +61,7 @@ fn main() { .arrange::>() .reduce_abelian::<_, _, _, PreferredSpine<[u8],(),_,_>>("distinct", |_| (), |_,_,output| output.push(((), 1))); - keys.join_core(&data, |k,_v1,_v2| { - println!("{:?}", k.text); - Option::<((),isize,isize)>::None - }) + keys.join_core(&data, |_k, &(), &()| Option::<()>::None) .probe_with(&mut probe); }, _ => { @@ -122,4 +119,4 @@ fn main() { println!("{:?}\tshut down", timer2.elapsed()); -} \ No newline at end of file +} diff --git a/src/trace/implementations/mod.rs b/src/trace/implementations/mod.rs index cd0b8fd9a..128ec0bf1 100644 --- a/src/trace/implementations/mod.rs +++ b/src/trace/implementations/mod.rs @@ -149,7 +149,7 @@ impl PreferredContainer for T { } impl PreferredContainer for [T] { - type Container = SliceContainer2; + type Container = SliceContainer; } /// An update and layout description based on preferred containers. @@ -320,7 +320,7 @@ impl BatchContainer for OffsetList { } } -pub use self::containers::{BatchContainer, SliceContainer, SliceContainer2}; +pub use self::containers::{BatchContainer, SliceContainer}; /// Containers for data that resemble `Vec`, with leaner implementations. pub mod containers { @@ -559,132 +559,4 @@ pub mod containers { } } } - - /// A container that accepts slices `[B::Item]`. - pub struct SliceContainer2 { - text: String, - /// Offsets that bound each contained slice. - /// - /// The length will be one greater than the number of contained slices, - /// starting with zero and ending with `self.inner.len()`. - offsets: Vec, - /// An inner container for sequences of `B` that dereferences to a slice. - inner: Vec, - } - - /// Welcome to GATs! - pub struct Greetings<'a, B> { - /// Text that decorates the data. - pub text: Option<&'a str>, - /// The data itself. - pub slice: &'a [B], - } - - impl<'a, B> Copy for Greetings<'a, B> { } - impl<'a, B> Clone for Greetings<'a, B> { - fn clone(&self) -> Self { *self } - } - - use std::cmp::Ordering; - impl<'a, 'b, B: Ord> PartialEq> for Greetings<'b, B> { - fn eq(&self, other: &Greetings<'a, B>) -> bool { - self.slice.eq(other.slice) - } - } - impl<'a, B: Ord> Eq for Greetings<'a, B> { } - impl<'a, 'b, B: Ord> PartialOrd> for Greetings<'b, B> { - fn partial_cmp(&self, other: &Greetings<'a, B>) -> Option { - self.slice.partial_cmp(other.slice) - } - } - impl<'a, B: Ord> Ord for Greetings<'a, B> { - fn cmp(&self, other: &Self) -> Ordering { - self.partial_cmp(other).unwrap() - } - } - - impl<'a, B: Ord + Clone> MyTrait<'a> for Greetings<'a, B> { - type Owned = Vec; - fn into_owned(self) -> Self::Owned { self.slice.to_vec() } - fn clone_onto(&self, other: &mut Self::Owned) { - self.slice.clone_into(other); - } - fn compare(&self, other: &Self::Owned) -> std::cmp::Ordering { - self.slice.cmp(&other[..]) - } - fn borrow_as(other: &'a Self::Owned) -> Self { - Self { - text: None, - slice: &other[..], - } - } - } - - impl BatchContainer for SliceContainer2 - where - B: Ord + Clone + Sized + 'static, - { - type PushItem = Vec; - type ReadItem<'a> = Greetings<'a, B>; - fn push(&mut self, item: Vec) { - for x in item.into_iter() { - self.inner.push(x); - } - self.offsets.push(self.inner.len()); - } - fn copy_push(&mut self, item: &Vec) { - self.copy(<_ as MyTrait>::borrow_as(item)); - } - fn copy(&mut self, item: Self::ReadItem<'_>) { - for x in item.slice.iter() { - self.inner.copy(x); - } - self.offsets.push(self.inner.len()); - } - fn copy_range(&mut self, other: &Self, start: usize, end: usize) { - for index in start .. end { - self.copy(other.index(index)); - } - } - fn with_capacity(size: usize) -> Self { - let mut offsets = Vec::with_capacity(size + 1); - offsets.push(0); - Self { - text: format!("Hello!"), - offsets, - inner: Vec::with_capacity(size), - } - } - fn merge_capacity(cont1: &Self, cont2: &Self) -> Self { - let mut offsets = Vec::with_capacity(cont1.inner.len() + cont2.inner.len() + 1); - offsets.push(0); - Self { - text: format!("Hello!"), - offsets, - inner: Vec::with_capacity(cont1.inner.len() + cont2.inner.len()), - } - } - fn index(&self, index: usize) -> Self::ReadItem<'_> { - let lower = self.offsets[index]; - let upper = self.offsets[index+1]; - Greetings { - text: Some(&self.text), - slice: &self.inner[lower .. upper], - } - } - fn len(&self) -> usize { - self.offsets.len() - 1 - } - } - - /// Default implementation introduces a first offset. - impl Default for SliceContainer2 { - fn default() -> Self { - Self { - text: format!("Hello!"), - offsets: vec![0], - inner: Default::default(), - } - } - } } diff --git a/src/trace/implementations/rhh.rs b/src/trace/implementations/rhh.rs index 088055507..8389b62a6 100644 --- a/src/trace/implementations/rhh.rs +++ b/src/trace/implementations/rhh.rs @@ -68,7 +68,14 @@ where ::Output: PartialOrd { impl HashOrdered for HashWrapper { } -impl Hashable for HashWrapper { +impl Hashable for HashWrapper { + type Output = T::Output; + fn hashed(&self) -> Self::Output { self.inner.hashed() } +} + +impl HashOrdered for &HashWrapper { } + +impl Hashable for &HashWrapper { type Output = T::Output; fn hashed(&self) -> Self::Output { self.inner.hashed() } }