Skip to content

Commit 9731d7f

Browse files
authored
Cleanup, fix rhh example (#492)
Signed-off-by: Moritz Hoffmann <[email protected]>
1 parent 9171e73 commit 9731d7f

File tree

3 files changed

+19
-143
lines changed

3 files changed

+19
-143
lines changed

examples/spines.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ fn main() {
4141
keys.join_core(&data, |_k, &(), &()| Option::<()>::None)
4242
.probe_with(&mut probe);
4343
},
44-
// "rhh" => {
45-
// use differential_dataflow::trace::implementations::rhh::{HashWrapper, VecSpine};
46-
// let data = data.map(|x| HashWrapper { inner: x }).arrange::<VecSpine<_,(),_,_>>();
47-
// let keys = keys.map(|x| HashWrapper { inner: x }).arrange::<VecSpine<_,(),_,_>>();
48-
// keys.join_core(&data, |_k, &(), &()| Option::<()>::None)
49-
// .probe_with(&mut probe);
50-
// },
44+
"rhh" => {
45+
use differential_dataflow::trace::implementations::rhh::{HashWrapper, VecSpine};
46+
let data = data.map(|x| HashWrapper { inner: x }).arrange::<VecSpine<_,(),_,_>>();
47+
let keys = keys.map(|x| HashWrapper { inner: x }).arrange::<VecSpine<_,(),_,_>>();
48+
keys.join_core(&data, |_k, &(), &()| Option::<()>::None)
49+
.probe_with(&mut probe);
50+
},
5151
"slc" => {
5252

5353
use differential_dataflow::trace::implementations::ord_neu::PreferredSpine;
@@ -61,10 +61,7 @@ fn main() {
6161
.arrange::<PreferredSpine<[u8],u8,_,_>>()
6262
.reduce_abelian::<_, _, _, PreferredSpine<[u8],(),_,_>>("distinct", |_| (), |_,_,output| output.push(((), 1)));
6363

64-
keys.join_core(&data, |k,_v1,_v2| {
65-
println!("{:?}", k.text);
66-
Option::<((),isize,isize)>::None
67-
})
64+
keys.join_core(&data, |_k, &(), &()| Option::<()>::None)
6865
.probe_with(&mut probe);
6966
},
7067
_ => {
@@ -122,4 +119,4 @@ fn main() {
122119

123120
println!("{:?}\tshut down", timer2.elapsed());
124121

125-
}
122+
}

src/trace/implementations/mod.rs

Lines changed: 2 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl<T: Ord + Clone + 'static> PreferredContainer for T {
149149
}
150150

151151
impl<T: Ord + Clone + 'static> PreferredContainer for [T] {
152-
type Container = SliceContainer2<T>;
152+
type Container = SliceContainer<T>;
153153
}
154154

155155
/// An update and layout description based on preferred containers.
@@ -320,7 +320,7 @@ impl BatchContainer for OffsetList {
320320
}
321321
}
322322

323-
pub use self::containers::{BatchContainer, SliceContainer, SliceContainer2};
323+
pub use self::containers::{BatchContainer, SliceContainer};
324324

325325
/// Containers for data that resemble `Vec<T>`, with leaner implementations.
326326
pub mod containers {
@@ -559,132 +559,4 @@ pub mod containers {
559559
}
560560
}
561561
}
562-
563-
/// A container that accepts slices `[B::Item]`.
564-
pub struct SliceContainer2<B> {
565-
text: String,
566-
/// Offsets that bound each contained slice.
567-
///
568-
/// The length will be one greater than the number of contained slices,
569-
/// starting with zero and ending with `self.inner.len()`.
570-
offsets: Vec<usize>,
571-
/// An inner container for sequences of `B` that dereferences to a slice.
572-
inner: Vec<B>,
573-
}
574-
575-
/// Welcome to GATs!
576-
pub struct Greetings<'a, B> {
577-
/// Text that decorates the data.
578-
pub text: Option<&'a str>,
579-
/// The data itself.
580-
pub slice: &'a [B],
581-
}
582-
583-
impl<'a, B> Copy for Greetings<'a, B> { }
584-
impl<'a, B> Clone for Greetings<'a, B> {
585-
fn clone(&self) -> Self { *self }
586-
}
587-
588-
use std::cmp::Ordering;
589-
impl<'a, 'b, B: Ord> PartialEq<Greetings<'a, B>> for Greetings<'b, B> {
590-
fn eq(&self, other: &Greetings<'a, B>) -> bool {
591-
self.slice.eq(other.slice)
592-
}
593-
}
594-
impl<'a, B: Ord> Eq for Greetings<'a, B> { }
595-
impl<'a, 'b, B: Ord> PartialOrd<Greetings<'a, B>> for Greetings<'b, B> {
596-
fn partial_cmp(&self, other: &Greetings<'a, B>) -> Option<Ordering> {
597-
self.slice.partial_cmp(other.slice)
598-
}
599-
}
600-
impl<'a, B: Ord> Ord for Greetings<'a, B> {
601-
fn cmp(&self, other: &Self) -> Ordering {
602-
self.partial_cmp(other).unwrap()
603-
}
604-
}
605-
606-
impl<'a, B: Ord + Clone> MyTrait<'a> for Greetings<'a, B> {
607-
type Owned = Vec<B>;
608-
fn into_owned(self) -> Self::Owned { self.slice.to_vec() }
609-
fn clone_onto(&self, other: &mut Self::Owned) {
610-
self.slice.clone_into(other);
611-
}
612-
fn compare(&self, other: &Self::Owned) -> std::cmp::Ordering {
613-
self.slice.cmp(&other[..])
614-
}
615-
fn borrow_as(other: &'a Self::Owned) -> Self {
616-
Self {
617-
text: None,
618-
slice: &other[..],
619-
}
620-
}
621-
}
622-
623-
impl<B> BatchContainer for SliceContainer2<B>
624-
where
625-
B: Ord + Clone + Sized + 'static,
626-
{
627-
type PushItem = Vec<B>;
628-
type ReadItem<'a> = Greetings<'a, B>;
629-
fn push(&mut self, item: Vec<B>) {
630-
for x in item.into_iter() {
631-
self.inner.push(x);
632-
}
633-
self.offsets.push(self.inner.len());
634-
}
635-
fn copy_push(&mut self, item: &Vec<B>) {
636-
self.copy(<_ as MyTrait>::borrow_as(item));
637-
}
638-
fn copy(&mut self, item: Self::ReadItem<'_>) {
639-
for x in item.slice.iter() {
640-
self.inner.copy(x);
641-
}
642-
self.offsets.push(self.inner.len());
643-
}
644-
fn copy_range(&mut self, other: &Self, start: usize, end: usize) {
645-
for index in start .. end {
646-
self.copy(other.index(index));
647-
}
648-
}
649-
fn with_capacity(size: usize) -> Self {
650-
let mut offsets = Vec::with_capacity(size + 1);
651-
offsets.push(0);
652-
Self {
653-
text: format!("Hello!"),
654-
offsets,
655-
inner: Vec::with_capacity(size),
656-
}
657-
}
658-
fn merge_capacity(cont1: &Self, cont2: &Self) -> Self {
659-
let mut offsets = Vec::with_capacity(cont1.inner.len() + cont2.inner.len() + 1);
660-
offsets.push(0);
661-
Self {
662-
text: format!("Hello!"),
663-
offsets,
664-
inner: Vec::with_capacity(cont1.inner.len() + cont2.inner.len()),
665-
}
666-
}
667-
fn index(&self, index: usize) -> Self::ReadItem<'_> {
668-
let lower = self.offsets[index];
669-
let upper = self.offsets[index+1];
670-
Greetings {
671-
text: Some(&self.text),
672-
slice: &self.inner[lower .. upper],
673-
}
674-
}
675-
fn len(&self) -> usize {
676-
self.offsets.len() - 1
677-
}
678-
}
679-
680-
/// Default implementation introduces a first offset.
681-
impl<B> Default for SliceContainer2<B> {
682-
fn default() -> Self {
683-
Self {
684-
text: format!("Hello!"),
685-
offsets: vec![0],
686-
inner: Default::default(),
687-
}
688-
}
689-
}
690562
}

src/trace/implementations/rhh.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,14 @@ where <T as Hashable>::Output: PartialOrd {
6868

6969
impl<T: std::hash::Hash + Hashable> HashOrdered for HashWrapper<T> { }
7070

71-
impl<T: std::hash::Hash + Hashable> Hashable for HashWrapper<T> {
71+
impl<T: std::hash::Hash + Hashable> Hashable for HashWrapper<T> {
72+
type Output = T::Output;
73+
fn hashed(&self) -> Self::Output { self.inner.hashed() }
74+
}
75+
76+
impl<T: std::hash::Hash + Hashable> HashOrdered for &HashWrapper<T> { }
77+
78+
impl<T: std::hash::Hash + Hashable> Hashable for &HashWrapper<T> {
7279
type Output = T::Output;
7380
fn hashed(&self) -> Self::Output { self.inner.hashed() }
7481
}

0 commit comments

Comments
 (0)