Skip to content
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
48 changes: 48 additions & 0 deletions timely/src/progress/frontier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ impl<T: PartialOrder> Antichain<T> {
}
}

impl<T: PartialOrder> std::iter::FromIterator<T> for Antichain<T> {
fn from_iter<I>(iterator: I) -> Self
where
I: IntoIterator<Item=T>
{
let mut result = Self::new();
result.extend(iterator);
result
}
}

impl<T> Antichain<T> {

/// Creates a new empty `Antichain`.
Expand Down Expand Up @@ -229,6 +240,19 @@ impl<T: Clone> Clone for Antichain<T> {

impl<T: TotalOrder> TotalOrder for Antichain<T> { }

impl<T: TotalOrder> Antichain<T> {
/// Convert to the at most one element the antichain contains.
pub fn into_option(mut self) -> Option<T> {
debug_assert!(self.len() <= 1);
self.elements.pop()
}
/// Return a reference to the at most one element the antichain contains.
pub fn as_option(&self) -> Option<&T> {
debug_assert!(self.len() <= 1);
self.elements.last()
}
}

impl<T: Ord+std::hash::Hash> std::hash::Hash for Antichain<T> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
let mut temp = self.elements.iter().collect::<Vec<_>>();
Expand Down Expand Up @@ -610,6 +634,20 @@ impl<'a, T: PartialOrder+Ord+Clone> From<AntichainRef<'a, T>> for MutableAnticha
}
}

impl<T> std::iter::FromIterator<(T, i64)> for MutableAntichain<T>
where
T: Clone + PartialOrder + Ord,
{
fn from_iter<I>(iterator: I) -> Self
where
I: IntoIterator<Item=(T, i64)>,
{
let mut result = Self::new();
result.update_iter(iterator);
result
}
}

/// A wrapper for elements of an antichain.
#[derive(Debug)]
pub struct AntichainRef<'a, T: 'a> {
Expand Down Expand Up @@ -711,6 +749,16 @@ impl<'a, T: PartialOrder> PartialOrder for AntichainRef<'a, T> {
}
}

impl<'a, T: TotalOrder> TotalOrder for AntichainRef<'a, T> { }

impl<'a, T: TotalOrder> AntichainRef<'a, T> {
/// Return a reference to the at most one element the antichain contains.
pub fn as_option(&self) -> Option<&T> {
debug_assert!(self.len() <= 1);
self.frontier.last()
}
}

impl<'a, T> ::std::ops::Deref for AntichainRef<'a, T> {
type Target = [T];
fn deref(&self) -> &Self::Target {
Expand Down