forked from TimelyDataflow/timely-dataflow
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
386cb45
commit ca85b95
Showing
4 changed files
with
61 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
//! Conversion to the `StreamCore` type from iterators. | ||
use crate::container::{PushContainer, PushInto}; | ||
use crate::Container; | ||
use crate::dataflow::operators::generic::operator::source; | ||
use crate::dataflow::{StreamCore, Scope}; | ||
|
||
/// Converts to a timely [StreamCore]. | ||
pub trait ToStream<C: Container> { | ||
/// Converts to a timely [StreamCore]. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ``` | ||
/// use timely::dataflow::operators::core::ToStream; | ||
/// use timely::dataflow::operators::Capture; | ||
/// use timely::dataflow::operators::capture::Extract; | ||
/// | ||
/// let (data1, data2) = timely::example(|scope| { | ||
/// let data1 = (0..3).to_stream(scope).capture(); | ||
/// let data2 = vec![0,1,2].to_stream(scope).capture(); | ||
/// (data1, data2) | ||
/// }); | ||
/// | ||
/// assert_eq!(data1.extract(), data2.extract()); | ||
/// ``` | ||
fn to_stream<S: Scope>(self, scope: &mut S) -> StreamCore<S, C>; | ||
} | ||
|
||
impl<C: PushContainer, I: IntoIterator+'static> ToStream<C> for I where I::Item: PushInto<C> { | ||
fn to_stream<S: Scope>(self, scope: &mut S) -> StreamCore<S, C> { | ||
|
||
source(scope, "ToStream", |capability, info| { | ||
|
||
// Acquire an activator, so that the operator can rescheduled itself. | ||
let activator = scope.activator_for(&info.address[..]); | ||
|
||
let mut iterator = self.into_iter().fuse(); | ||
let mut capability = Some(capability); | ||
|
||
move |output| { | ||
|
||
if let Some(element) = iterator.next() { | ||
let mut session = output.session(capability.as_ref().unwrap()); | ||
session.give(element); | ||
let n = 256 * crate::container::buffer::default_capacity::<I::Item>(); | ||
for element in iterator.by_ref().take(n - 1) { | ||
session.give(element); | ||
} | ||
activator.activate(); | ||
} | ||
else { | ||
capability = None; | ||
} | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.