[][src]Struct paragraphs::graph::Graph

pub struct Graph<Node, Data> where
    Node: ThreadExecute<Data>,
    Data: Send + Sync
{ /* fields omitted */ }

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]

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]

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]

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]

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]

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?

impl<'a, Node, Data> IntoIterator for &'a Graph<Node, Data> where
    Node: ThreadExecute<Data>,
    Data: Send + Sync
[src]

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?

impl<'a, Node, Data> IntoIterator for &'a mut Graph<Node, Data> where
    Node: ThreadExecute<Data>,
    Data: Send + Sync
[src]

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?

impl<Node: Debug, Data: Debug> Debug for Graph<Node, Data> where
    Node: ThreadExecute<Data>,
    Data: Send + Sync
[src]

Auto Trait Implementations

impl<Node, Data> Send for Graph<Node, Data>

impl<Node, Data> !Sync for Graph<Node, Data>

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> From for T[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

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?

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.