Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Product with flatcontainer #570

Merged
merged 2 commits into from
Jun 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 133 additions & 0 deletions timely/src/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<TO: Containerized, TI: Containerized> Containerized for Product<TO, TI> {
type Region = ProductRegion<TO::Region, TI::Region>;
}

/// Region to store [`Product`] timestamps.
#[derive(Default, Clone, Debug)]
pub struct ProductRegion<RO: Region, RI: Region> {
outer_region: RO,
inner_region: RI,
}

impl<RO: Region, RI: Region> Region for ProductRegion<RO, RI> {
type Owned = Product<RO::Owned, RI::Owned>;
type ReadItem<'a> = Product<RO::ReadItem<'a>, RI::ReadItem<'a>> where Self: 'a;
type Index = (RO::Index, RI::Index);

#[inline]
fn merge_regions<'a>(regions: impl Iterator<Item=&'a Self> + 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<Item=&'a Self> + 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<F: FnMut(usize, usize)>(&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<TOuter, TInner>
where
TOuter: IntoOwned<'a>,
TInner: IntoOwned<'a>,
{
type Owned = Product<TOuter::Owned, TInner::Owned>;

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<Product<RO::ReadItem<'a>, RI::ReadItem<'a>>> for ProductRegion<RO, RI>
where
RO: Region + ReserveItems<<RO as Region>::ReadItem<'a>> + 'a,
RI: Region + ReserveItems<<RI as Region>::ReadItem<'a>> + 'a,
{
#[inline]
fn reserve_items<I>(&mut self, items: I) where I: Iterator<Item=Product<RO::ReadItem<'a>, 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<TO, TI, RO, RI> Push<Product<TO, TI>> for ProductRegion<RO, RI>
where
RO: Region + Push<TO>,
RI: Region + Push<TI>,
{
#[inline]
fn push(&mut self, item: Product<TO, TI>) -> Self::Index {
(
self.outer_region.push(item.outer),
self.inner_region.push(item.inner)
)
}
}

impl<'a, TO, TI, RO, RI> Push<&'a Product<TO, TI>> for ProductRegion<RO, RI>
where
RO: Region + Push<&'a TO>,
RI: Region + Push<&'a TI>,
{
#[inline]
fn push(&mut self, item: &'a Product<TO, TI>) -> Self::Index {
(
self.outer_region.push(&item.outer),
self.inner_region.push(&item.inner)
)
}
}

impl<'a, TO, TI, RO, RI> Push<&&'a Product<TO, TI>> for ProductRegion<RO, RI>
where
RO: Region + Push<&'a TO>,
RI: Region + Push<&'a TI>,
{
#[inline]
fn push(&mut self, item: && 'a Product<TO, TI>) -> Self::Index {
(
self.outer_region.push(&item.outer),
self.inner_region.push(&item.inner)
)
}
}
}
}

/// Rust tuple ordered by the lexicographic order.
Expand Down
Loading