mod antichain;
mod product;
use crate::{
DBData, Scope,
algebra::{Lattice, PartialOrder},
trace::Batch,
};
use rkyv::{Archive, Deserialize, Serialize};
use size_of::SizeOf;
use std::{fmt::Debug, hash::Hash};
pub use antichain::{Antichain, AntichainRef};
pub use product::Product;
pub trait Timestamp: DBData + PartialOrder + Lattice {
const NESTING_DEPTH: usize;
type Nested: Timestamp;
type TimedBatch<B: Batch<Time = ()>>: Batch<Key = B::Key, Val = B::Val, Time = Self, R = B::R>;
fn minimum() -> Self;
fn clock_start() -> Self {
Self::minimum()
}
fn advance(&self, scope: Scope) -> Self;
fn recede(&self, scope: Scope) -> Self {
self.checked_recede(scope).unwrap()
}
fn checked_recede(&self, scope: Scope) -> Option<Self>;
fn epoch_start(&self, scope: Scope) -> Self;
fn epoch_end(&self, scope: Scope) -> Self;
}
#[derive(
Clone, Debug, Hash, PartialOrd, Ord, PartialEq, Eq, SizeOf, Archive, Serialize, Deserialize,
)]
#[archive_attr(derive(Ord, Eq, PartialEq, PartialOrd, Hash))]
#[archive(compare(PartialEq, PartialOrd))]
#[archive_attr(doc(hidden))]
pub struct UnitTimestamp;
impl Default for UnitTimestamp {
fn default() -> Self {
UnitTimestamp
}
}
impl PartialOrder for UnitTimestamp {
fn less_equal(&self, _other: &Self) -> bool {
true
}
}
impl Lattice for UnitTimestamp {
fn join(&self, _other: &Self) -> Self {
UnitTimestamp
}
fn meet(&self, _other: &Self) -> Self {
UnitTimestamp
}
}
impl Timestamp for UnitTimestamp {
const NESTING_DEPTH: usize = 0;
type Nested = ();
type TimedBatch<B: Batch<Time = ()>> = B::Timed<Self>;
fn minimum() -> Self {
UnitTimestamp
}
fn advance(&self, _scope: Scope) -> Self {
UnitTimestamp
}
fn recede(&self, _scope: Scope) -> Self {
UnitTimestamp
}
fn checked_recede(&self, _scope: Scope) -> Option<Self> {
None
}
fn epoch_start(&self, _scope: Scope) -> Self {
UnitTimestamp
}
fn epoch_end(&self, _scope: Scope) -> Self {
UnitTimestamp
}
}
impl Timestamp for () {
const NESTING_DEPTH: usize = 0;
type TimedBatch<B: Batch<Time = ()>> = B;
type Nested = Product<u32, u32>;
fn minimum() -> Self {}
fn advance(&self, _scope: Scope) -> Self {}
fn recede(&self, _scope: Scope) -> Self {}
fn checked_recede(&self, _scope: Scope) -> Option<Self> {
Some(())
}
fn epoch_start(&self, _scope: Scope) -> Self {}
fn epoch_end(&self, _scope: Scope) -> Self {}
}
impl Timestamp for u32 {
const NESTING_DEPTH: usize = 0;
type Nested = Product<u32, u32>;
type TimedBatch<B: Batch<Time = ()>> = B::Timed<Self>;
fn minimum() -> Self {
0
}
fn advance(&self, _scope: Scope) -> Self {
self + 1
}
fn recede(&self, _scope: Scope) -> Self {
self - 1
}
fn checked_recede(&self, _scope: Scope) -> Option<Self> {
self.checked_sub(1)
}
fn epoch_start(&self, _scope: Scope) -> Self {
0
}
fn epoch_end(&self, _scope: Scope) -> Self {
Self::MAX
}
}