[−][src]Struct paragraphs::graph::Graph
A computation graph. Nodes are executed concurrently wherever possible. Each graph manages its own threadpool, so although it may be possible to creat higher-order graphs, it is generally not advisable.
Methods
impl<Node: 'static, Data: 'static> Graph<Node, Data> where
Node: ThreadExecute<Data>,
Data: Send + Sync,
[src]
Node: ThreadExecute<Data>,
Data: Send + Sync,
pub fn new(num_threads: usize) -> Graph<Node, Data>
[src]
Creates a new graph.
Arguments
num_threads
- The number of threads available to the graph.
Example
use paragraphs::{Graph, ThreadExecute}; use std::sync::Arc; struct MyNode; struct MyData; impl ThreadExecute<MyData> for MyNode { fn execute(&mut self, inputs: Vec<Arc<MyData>>) -> Option<MyData> { return Some(MyData{}); } } let graph: Graph<MyNode, MyData> = Graph::new(8);
pub fn len(&self) -> usize
[src]
Returns the number of nodes in the graph.
pub fn get(&self, index: usize) -> Option<&Node>
[src]
Gets an Option containing a reference to the node at the specified index.
Arguments
index
- The index of the node.
pub fn get_mut(&mut self, index: usize) -> Option<&mut Node>
[src]
Gets an Option containing a mutable referenece to the node at the specified index.
Arguments
index
- The index of the node.
pub fn add<Container, Elem>(&mut self, node: Node, inputs: Container) -> usize where
Container: IntoIterator<Item = Elem>,
Elem: Borrow<usize>,
[src]
Container: IntoIterator<Item = Elem>,
Elem: Borrow<usize>,
Adds a new node to the graph.
Arguments
node
- The node to add to the graph.inputs
- The indices of the inputs to the node. All inputs specified must already be present in the graph, or the function panics. Inputs may be specified more than once.
Example
use paragraphs::Graph; let mut graph = Graph::new(8); let node0 = graph.add(MyNode{}, &[]); let node1 = graph.add(MyNode{}, &[node0, node0]);
pub fn compile<Container, Elem>(&self, fetches: Container) -> Recipe where
Container: IntoIterator<Item = Elem>,
Elem: Borrow<usize>,
[src]
Container: IntoIterator<Item = Elem>,
Elem: Borrow<usize>,
Generates a Recipe that can be used to compute the specified outputs.
Arguments
fetches
- The indices of the nodes to fetch. May contain duplicates. Panics if no nodes are specified.
Example
// This recipe can be used to fetch the result of node1. let node1_recipe = graph.compile(&[node1]);
pub fn run(
&mut self,
recipe: &Recipe,
inputs_map: HashMap<usize, Vec<Data>>
) -> HashMap<usize, Data>
[src]
&mut self,
recipe: &Recipe,
inputs_map: HashMap<usize, Vec<Data>>
) -> HashMap<usize, Data>
Executes the nodes specified by the recipe using the provided inputs.
Arguments
recipe
- The recipe to execute. All outputs of the recipe are fetched.inputs_map
- Inputs for each input node. Panics if inputs are missing.
Example
use std::collections::HashMap; use std::iter::FromIterator; let inputs_map = HashMap::from_iter(vec!( (node0, vec![MyData{}]), )); let outputs = graph.run(&node1_recipe, inputs_map);
Trait Implementations
impl<Node, Data> IntoIterator for Graph<Node, Data> where
Node: ThreadExecute<Data>,
Data: Send + Sync,
[src]
Node: ThreadExecute<Data>,
Data: Send + Sync,
type Item = Node
The type of the elements being iterated over.
type IntoIter = Map<IntoIter<Option<Node>>, fn(_: Option<Node>) -> Node>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a, Node, Data> IntoIterator for &'a Graph<Node, Data> where
Node: ThreadExecute<Data>,
Data: Send + Sync,
[src]
Node: ThreadExecute<Data>,
Data: Send + Sync,
type Item = &'a Node
The type of the elements being iterated over.
type IntoIter = Map<Iter<'a, Option<Node>>, fn(_: &Option<Node>) -> &Node>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a, Node, Data> IntoIterator for &'a mut Graph<Node, Data> where
Node: ThreadExecute<Data>,
Data: Send + Sync,
[src]
Node: ThreadExecute<Data>,
Data: Send + Sync,
type Item = &'a mut Node
The type of the elements being iterated over.
type IntoIter = Map<IterMut<'a, Option<Node>>, fn(_: &mut Option<Node>) -> &mut Node>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<Node: Debug, Data: Debug> Debug for Graph<Node, Data> where
Node: ThreadExecute<Data>,
Data: Send + Sync,
[src]
Node: ThreadExecute<Data>,
Data: Send + Sync,
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
type Item = <I as Iterator>::Item
The type of the elements being iterated over.
type IntoIter = I
Which kind of iterator are we turning this into?
fn into_iter(self) -> I
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,