diff --git a/timely/src/order.rs b/timely/src/order.rs index cd4796fae..e9050b3f4 100644 --- a/timely/src/order.rs +++ b/timely/src/order.rs @@ -57,6 +57,7 @@ implement_partial!(u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isiz implement_total!(u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize, (), ::std::time::Duration,); pub use product::Product; +pub use product::flatcontainer::ProductRegion as FlatProductRegion; /// A pair of timestamps, partially ordered by the product order. mod product { use std::fmt::{Formatter, Error, Debug}; @@ -188,6 +189,138 @@ mod product { self.inner_region.heap_size(callback); } } + + pub mod flatcontainer { + use timely_container::flatcontainer::{Containerized, IntoOwned, Push, Region, ReserveItems}; + use super::Product; + + impl Containerized for Product { + type Region = ProductRegion; + } + + /// Region to store [`Product`] timestamps. + #[derive(Default, Clone, Debug)] + pub struct ProductRegion { + outer_region: RO, + inner_region: RI, + } + + impl Region for ProductRegion { + type Owned = Product; + type ReadItem<'a> = Product, RI::ReadItem<'a>> where Self: 'a; + type Index = (RO::Index, RI::Index); + + #[inline] + fn merge_regions<'a>(regions: impl Iterator + Clone) -> Self where Self: 'a { + let outer_region = RO::merge_regions(regions.clone().map(|r| &r.outer_region)); + let inner_region = RI::merge_regions(regions.map(|r| &r.inner_region)); + Self { outer_region, inner_region } + } + + #[inline] + fn index(&self, (outer, inner): Self::Index) -> Self::ReadItem<'_> { + Product::new(self.outer_region.index(outer), self.inner_region.index(inner)) + } + + #[inline] + fn reserve_regions<'a, I>(&mut self, regions: I) where Self: 'a, I: Iterator + Clone { + self.outer_region.reserve_regions(regions.clone().map(|r| &r.outer_region)); + self.inner_region.reserve_regions(regions.map(|r| &r.inner_region)); + } + + #[inline] + fn clear(&mut self) { + self.outer_region.clear(); + self.inner_region.clear(); + } + + #[inline] + fn heap_size(&self, mut callback: F) { + self.outer_region.heap_size(&mut callback); + self.inner_region.heap_size(callback); + } + + #[inline] + fn reborrow<'b, 'a: 'b>(item: Self::ReadItem<'a>) -> Self::ReadItem<'b> where Self: 'a { + Product::new(RO::reborrow(item.outer), RI::reborrow(item.inner)) + } + } + + impl<'a, TOuter, TInner> IntoOwned<'a> for Product + where + TOuter: IntoOwned<'a>, + TInner: IntoOwned<'a>, + { + type Owned = Product; + + fn into_owned(self) -> Self::Owned { + Product::new(self.outer.into_owned(), self.inner.into_owned()) + } + + fn clone_onto(self, other: &mut Self::Owned) { + self.outer.clone_onto(&mut other.outer); + self.inner.clone_onto(&mut other.inner); + } + + fn borrow_as(owned: &'a Self::Owned) -> Self { + Product::new(IntoOwned::borrow_as(&owned.outer), IntoOwned::borrow_as(&owned.inner)) + } + } + + impl<'a, RO, RI> ReserveItems, RI::ReadItem<'a>>> for ProductRegion + where + RO: Region + ReserveItems<::ReadItem<'a>> + 'a, + RI: Region + ReserveItems<::ReadItem<'a>> + 'a, + { + #[inline] + fn reserve_items(&mut self, items: I) where I: Iterator, RI::ReadItem<'a>>> + Clone { + self.outer_region.reserve_items(items.clone().map(|i| i.outer)); + self.inner_region.reserve_items(items.clone().map(|i| i.inner)); + } + } + + impl Push> for ProductRegion + where + RO: Region + Push, + RI: Region + Push, + { + #[inline] + fn push(&mut self, item: Product) -> Self::Index { + ( + self.outer_region.push(item.outer), + self.inner_region.push(item.inner) + ) + } + } + + impl<'a, TO, TI, RO, RI> Push<&'a Product> for ProductRegion + where + RO: Region + Push<&'a TO>, + RI: Region + Push<&'a TI>, + { + #[inline] + fn push(&mut self, item: &'a Product) -> Self::Index { + ( + self.outer_region.push(&item.outer), + self.inner_region.push(&item.inner) + ) + } + } + + impl<'a, TO, TI, RO, RI> Push<&&'a Product> for ProductRegion + where + RO: Region + Push<&'a TO>, + RI: Region + Push<&'a TI>, + { + #[inline] + fn push(&mut self, item: && 'a Product) -> Self::Index { + ( + self.outer_region.push(&item.outer), + self.inner_region.push(&item.inner) + ) + } + } + } } /// Rust tuple ordered by the lexicographic order.