use std::fmt::Debug;
use std::any::Any;
use std::default::Default;
use std::hash::Hash;
use crate::communication::Data;
use crate::order::PartialOrder;
pub trait Timestamp: Clone+Eq+PartialOrder+Default+Debug+Send+Any+Data+Hash+Ord {
type Summary : PathSummary<Self> + 'static;
}
pub trait PathSummary<T> : Clone+'static+Eq+PartialOrder+Debug+Default {
fn results_in(&self, src: &T) -> Option<T>;
fn followed_by(&self, other: &Self) -> Option<Self>;
}
impl Timestamp for () { type Summary = (); }
impl PathSummary<()> for () {
#[inline(always)] fn results_in(&self, _src: &()) -> Option<()> { Some(()) }
#[inline(always)] fn followed_by(&self, _other: &()) -> Option<()> { Some(()) }
}
macro_rules! implement_timestamp_add {
($($index_type:ty,)*) => (
$(
impl Timestamp for $index_type { type Summary = $index_type; }
impl PathSummary<$index_type> for $index_type {
#[inline]
fn results_in(&self, src: &$index_type) -> Option<$index_type> { self.checked_add(*src) }
#[inline]
fn followed_by(&self, other: &$index_type) -> Option<$index_type> { self.checked_add(*other) }
}
)*
)
}
implement_timestamp_add!(usize, u64, u32, u16, u8, i32, ::std::time::Duration,);
pub use self::refines::Refines;
mod refines {
use crate::progress::Timestamp;
pub trait Refines<T: Timestamp> : Timestamp {
fn to_inner(other: T) -> Self;
fn to_outer(self) -> T;
fn summarize(path: <Self as Timestamp>::Summary) -> <T as Timestamp>::Summary;
}
impl<T: Timestamp> Refines<T> for T {
fn to_inner(other: T) -> T { other }
fn to_outer(self) -> T { self }
fn summarize(path: <T as Timestamp>::Summary) -> <T as Timestamp>::Summary { path }
}
macro_rules! implement_refines_empty {
($($index_type:ty,)*) => (
$(
impl Refines<()> for $index_type {
fn to_inner(_: ()) -> $index_type { Default::default() }
fn to_outer(self) -> () { () }
fn summarize(_: <$index_type as Timestamp>::Summary) -> () { () }
}
)*
)
}
implement_refines_empty!(usize, u64, u32, u16, u8, i32, ::std::time::Duration,);
}