[][src]Trait outils::graph::dynconn::DynamicWeightedComponent

pub trait DynamicWeightedComponent<W = EmptyWeight, Ix = DefaultIndexType> where
    W: WeightType,
    Ix: IndexType
{ fn set_vertex_weight(&mut self, v: VertexIndex<Ix>, weight: W) -> Option<W>;
fn vertex_weight(&self, v: VertexIndex<Ix>) -> Option<&W>;
fn component_weight(&self, v: VertexIndex<Ix>) -> Option<&W>;
fn adjust_vertex_weight(
        &mut self,
        v: VertexIndex<Ix>,
        f: &dyn Fn(&mut W)
    ) -> Option<&W>; }

This trait defines the fundamental operations of a dynamic graph related to vertex weights, that can be applied to a connected sub-graph, that is, the connected components of the graph.

Required methods

fn set_vertex_weight(&mut self, v: VertexIndex<Ix>, weight: W) -> Option<W>

Set the weight of the vertex indexed by v to weight and update the weight of the component this vertex belongs to. If v was a valid index, the old weight is returned.

fn vertex_weight(&self, v: VertexIndex<Ix>) -> Option<&W>

Immutably access the weight of the vertex indexed by v.

fn component_weight(&self, v: VertexIndex<Ix>) -> Option<&W>

Immutably access the weight of the component to which the vertex indexed by v belongs.

fn adjust_vertex_weight(
    &mut self,
    v: VertexIndex<Ix>,
    f: &dyn Fn(&mut W)
) -> Option<&W>

Change the weight of the vertex indexed by v by applying the closure f. After applying the closure, the weight of the component this vertex belongs to will be updated accordingly. If v was a valid index a reference to the changed weight is returned.

Loading content...

Implementors

impl<W> DynamicWeightedComponent<W, usize> for DynamicGraph<W> where
    W: WeightType
[src]

fn set_vertex_weight(&mut self, v: VertexIndex, weight: W) -> Option<W>[src]

Set the weight of the vertex indexed by v to weight and update the weight of the component this vertex belongs to. If v was a valid index, the old weight is returned.

use outils::prelude::*;

// Construct a dynamic graph with weights of type usize and a fixed number of 10 vertices
// with an expected degree (i.e. number of adjacent edges) of 3.
let mut graph: DynamicGraph<usize> = DynamicGraph::new(10, 3);

let a = VertexIndex(0);
assert_eq!(graph.set_vertex_weight(a, 2), Some(0));

fn vertex_weight(&self, v: VertexIndex) -> Option<&W>[src]

Immutably access the weight of the vertex indexed by v.

fn component_weight(&self, v: VertexIndex) -> Option<&W>[src]

Immutably access the weight of the component to which the vertex indexed by v belongs.

use outils::prelude::*;

// Construct a dynamic graph with weights of type usize and a fixed number of 10 vertices
// with an expected degree (i.e. number of adjacent edges) of 3.
let mut graph: DynamicGraph<usize> = DynamicGraph::new(10, 3);

let a = VertexIndex(0);
let b = VertexIndex(1);
let c = VertexIndex(2);
let d = VertexIndex(3);

graph.set_vertex_weight(a, 1);
graph.set_vertex_weight(b, 1);
graph.set_vertex_weight(c, 1);
graph.set_vertex_weight(d, 1);

// Create component {a, b, c, d} - since all vertices have a weight of 1, the resulting
// component should have a weight of 4.
let ab = graph.insert_edge(a, b).expect("No reason to fail here");
let bc = graph.insert_edge(b, c).expect("No reason to fail here");
let bd = graph.insert_edge(b, d).expect("No reason to fail here");
let da = graph.insert_edge(a, b).expect("No reason to fail here"); // Non-spanning edge!

assert_eq!(graph.component_weight(a), Some(&4));

fn adjust_vertex_weight(
    &mut self,
    v: VertexIndex,
    f: &dyn Fn(&mut W)
) -> Option<&W>
[src]

Change the weight of the vertex indexed by v by applying the closure f. After applying the closure, the weight of the component this vertex belongs to will be updated accordingly. If v was a valid index a reference to the changed weight is returned.

use outils::prelude::*;

// Construct a dynamic graph with weights of type usize and a fixed number of 10 vertices
// with an expected degree (i.e. number of adjacent edges) of 3.
let mut graph: DynamicGraph<usize> = DynamicGraph::new(10, 3);

let a = VertexIndex(0);
assert_eq!(graph.adjust_vertex_weight(a, &|w: &mut usize| *w += 2), Some(&2));
Loading content...