use std::cell::RefCell;
use progress::{Timestamp, Operate, Subgraph};
use progress::nested::{Source, Target};
use timely_communication::Allocate;
pub mod root;
pub mod child;
pub use self::child::Child;
pub use self::root::Root;
pub trait ScopeParent: Allocate+Clone {
type Timestamp : Timestamp;
fn new_identifier(&mut self) -> usize;
}
pub trait Scope: ScopeParent {
fn name(&self) -> String;
fn addr(&self) -> Vec<usize>;
fn add_edge(&self, source: Source, target: Target);
fn add_operator<SC: Operate<Self::Timestamp>+'static>(&mut self, scope: SC) -> usize;
fn add_operator_with_index<SC: Operate<Self::Timestamp>+'static>(&mut self, scope: SC, index: usize);
fn new_subscope<T: Timestamp>(&mut self) -> Subgraph<Self::Timestamp, T>;
#[inline]
fn scoped<T: Timestamp, R, F:FnOnce(&mut Child<Self, T>)->R>(&mut self, func: F) -> R {
let subscope = RefCell::new(self.new_subscope());
let result = {
let mut builder = Child {
subgraph: &subscope,
parent: self.clone(),
};
func(&mut builder)
};
let index = subscope.borrow().index;
self.add_operator_with_index(subscope.into_inner(), index);
result
}
}