Struct FilterMap

Source
pub struct FilterMap<'g, BaseNodeWeight, BaseEdgeWeight, NodeWeight, EdgeWeight, Graph: Graph<BaseNodeWeight, BaseEdgeWeight>> { /* private fields */ }
Expand description

FilterMap is a graph representation that is designed to abstractly implement a wide range of possible Queries on a Graph object.

Given an underlying base graph object, it can:

  • Create a subgraph, filtering out nodes and edges based on a provided condition. Indices remain stable under those transformations.
  • Apply transformations to the node and edge weights. The new weights can reference the weights of the old graph as rust objects.

However it is not possible to change the structure beyond that.

The most general way to create a FilterMap graph is to use the constructor general_filter_map, which applies filters and transformations at the same time, with the possibility to consider the entire graph structure for each individual graph element transformation. For most use cases the simpler, derived constructors that only do part of that might be more appropriate.

Note that the base graph is required to outlive the generated FilterMap Graph, since the graph structure is borrowed from the base graph.

Implementations§

Source§

impl<'g, BaseNodeWeight, BaseEdgeWeight, NodeWeight, EdgeWeight, Graph: Graph<BaseNodeWeight, BaseEdgeWeight>> FilterMap<'g, BaseNodeWeight, BaseEdgeWeight, NodeWeight, EdgeWeight, Graph>

Source

pub fn new( base_graph: &'g Graph, node_map: HashMap<Graph::NodeRef, NodeWeight>, edge_map: HashMap<Graph::EdgeRef, EdgeWeight>, ) -> Self

The most low level constructor offered by this module. Usually its more comfortable to use one of the functional constructors below.

Creates a new FilterMap Graph directly from the corresponding node and edge maps provided as HashMaps.

It is the responsibility of the callee to ensure that provided edges only point to valid node indices that haven’t been removed from the node map.

Source

pub fn general_filter_map<NodeFn, EdgeFn>( base_graph: &'g Graph, node_fn: NodeFn, edge_fn: EdgeFn, ) -> Self
where NodeFn: Fn(&'g Graph, Graph::NodeRef) -> Option<NodeWeight>, EdgeFn: Fn(&'g Graph, Graph::EdgeRef) -> Option<EdgeWeight>,

Creates a new Graph derived from the base graph, both filtering nodes and edges and mapping their weights to new values.

node_fn takes a function closure that can either return None, to remove that node from the derived graph, or Some(weight) to keep it and at the same time equip it with a possibly new value for weight. edge_fn works similarly but with edges.

By also passing a reference to the base graph into these closures this can be used to accomplish quite complex graph filtering and mapping. For example the this can be used to query the adjacent graph elements of the element currently considered.

For simpler cases it might be more appropriate to use one of the derived constructors.

Source

pub fn weight_filter_map<NodeFn, EdgeFn>( base_graph: &'g Graph, node_fn: NodeFn, edge_fn: EdgeFn, ) -> Self
where NodeFn: Fn(&'g BaseNodeWeight) -> Option<NodeWeight>, EdgeFn: Fn(&'g BaseEdgeWeight) -> Option<EdgeWeight>, BaseNodeWeight: 'g, BaseEdgeWeight: 'g,

Creates a new graph derived from the base graph, similarly to general_filter_map.

However, the function closures just take the respective node and edge weights as arguments, making the constructor less general but more convenient to use.

Source

pub fn weight_map<NodeFn, EdgeFn>( base_graph: &'g Graph, node_fn: NodeFn, edge_fn: EdgeFn, ) -> Self
where NodeFn: Fn(&'g BaseNodeWeight) -> NodeWeight, EdgeFn: Fn(&'g BaseEdgeWeight) -> EdgeWeight, BaseNodeWeight: 'g, BaseEdgeWeight: 'g,

Creates a new graph derived from the case graph, applying the respective transformation to each node and edge weight, without removing any graph elements.

Source§

impl<'g, NodeWeight, EdgeWeight, Graph: Graph<NodeWeight, EdgeWeight>> FilterMap<'g, NodeWeight, EdgeWeight, &'g NodeWeight, &'g EdgeWeight, Graph>

Source

pub fn weight_filter<NodeFn, EdgeFn>( base_graph: &'g Graph, node_fn: NodeFn, edge_fn: EdgeFn, ) -> Self
where NodeFn: Fn(&'g NodeWeight) -> bool, EdgeFn: Fn(&'g EdgeWeight) -> bool, NodeWeight: 'g, EdgeWeight: 'g,

Creates a new graph derived from the base graph, just filtering out nodes and edges based on a given condition on their weights.

Note that, instead of copying the weights into the new graph it adds a layer of references into the old graph.

Trait Implementations§

Source§

impl<'g, BaseNodeWeight, BaseEdgeWeight, NodeWeight, EdgeWeight, Graph: Graph<BaseNodeWeight, BaseEdgeWeight>> Graph<NodeWeight, EdgeWeight> for FilterMap<'g, BaseNodeWeight, BaseEdgeWeight, NodeWeight, EdgeWeight, Graph>

Source§

type NodeRef = <Graph as Graph<BaseNodeWeight, BaseEdgeWeight>>::NodeRef

NodeRef is the associated type for node references. Read more
Source§

type EdgeRef = <Graph as Graph<BaseNodeWeight, BaseEdgeWeight>>::EdgeRef

EdgeRef is the associated type for edge references. Read more
Source§

type AdjacentEdgesIterator<'a> = impl Iterator<Item = <Graph as Graph<BaseNodeWeight, BaseEdgeWeight>>::EdgeRef> + 'a where Self: 'a

Source§

type IncomingEdgesIterator<'a> = impl Iterator<Item = <Graph as Graph<BaseNodeWeight, BaseEdgeWeight>>::EdgeRef> + 'a where Self: 'a

Source§

type OutgoingEdgesIterator<'a> = impl Iterator<Item = <Graph as Graph<BaseNodeWeight, BaseEdgeWeight>>::EdgeRef> + 'a where Self: 'a

Source§

type NodeWeightsIterator<'a> = impl Iterator<Item = &'a NodeWeight> where Self: 'a, NodeWeight: 'a

Source§

type EdgeWeightsIterator<'a> = impl Iterator<Item = &'a EdgeWeight> where Self: 'a, EdgeWeight: 'a

Source§

type NodesIterator<'a> = impl Iterator<Item = <Graph as Graph<BaseNodeWeight, BaseEdgeWeight>>::NodeRef> + 'a where Self: 'a

Source§

type EdgesIterator<'a> = impl Iterator<Item = <Graph as Graph<BaseNodeWeight, BaseEdgeWeight>>::EdgeRef> + 'a where Self: 'a

Source§

fn is_directed(&self) -> bool

Checks if the edges of this graph are directed.
Source§

fn is_directed_edge(&self, edge: Self::EdgeRef) -> bool

Checks if the given edge is directed.
Source§

fn adjacent_edges(&self, node: Self::NodeRef) -> Self::AdjacentEdgesIterator<'_>

Gets a readonly handle of all adjacent edges of a node. Read more
Source§

fn incoming_edges(&self, node: Self::NodeRef) -> Self::IncomingEdgesIterator<'_>

Gets a readonly handle of all incoming edges of a node. Read more
Source§

fn outgoing_edges(&self, node: Self::NodeRef) -> Self::OutgoingEdgesIterator<'_>

Gets a readonly handle of all outgoing edges of a node. Read more
Source§

fn adjacent_nodes(&self, edge: Self::EdgeRef) -> (Self::NodeRef, Self::NodeRef)

Gets a readonly handle of the nodes an edge connects. Read more
Source§

fn node_weight(&self, node: Self::NodeRef) -> &NodeWeight

Retrieve weight from a node reference.
Source§

fn edge_weight(&self, edge: Self::EdgeRef) -> &EdgeWeight

Retrieve weight from an edge reference.
Source§

fn node_weights(&self) -> Self::NodeWeightsIterator<'_>

Returns an Iterator over all node weights.
Source§

fn edge_weights(&self) -> Self::EdgeWeightsIterator<'_>

Returns an Iterator over all edge weights.
Source§

fn nodes(&self) -> Self::NodesIterator<'_>

Returns an Iterator over all nodes by their references.
Source§

fn edges(&self) -> Self::EdgesIterator<'_>

Returns an Iterator over all edges by their references.
Source§

fn count_edges(&self) -> usize

Returns the number of edges in this graph.
Source§

fn count_nodes(&self) -> usize

Returns the number of nodes in this graph.
Source§

fn is_empty_graph(&self) -> bool

Tests if the given graph is empty.

Auto Trait Implementations§

§

impl<'g, BaseNodeWeight, BaseEdgeWeight, NodeWeight, EdgeWeight, Graph> Freeze for FilterMap<'g, BaseNodeWeight, BaseEdgeWeight, NodeWeight, EdgeWeight, Graph>

§

impl<'g, BaseNodeWeight, BaseEdgeWeight, NodeWeight, EdgeWeight, Graph> RefUnwindSafe for FilterMap<'g, BaseNodeWeight, BaseEdgeWeight, NodeWeight, EdgeWeight, Graph>
where Graph: RefUnwindSafe, <Graph as Graph<BaseNodeWeight, BaseEdgeWeight>>::NodeRef: RefUnwindSafe, NodeWeight: RefUnwindSafe, <Graph as Graph<BaseNodeWeight, BaseEdgeWeight>>::EdgeRef: RefUnwindSafe, EdgeWeight: RefUnwindSafe,

§

impl<'g, BaseNodeWeight, BaseEdgeWeight, NodeWeight, EdgeWeight, Graph> Send for FilterMap<'g, BaseNodeWeight, BaseEdgeWeight, NodeWeight, EdgeWeight, Graph>
where Graph: Sync, <Graph as Graph<BaseNodeWeight, BaseEdgeWeight>>::NodeRef: Send, NodeWeight: Send, <Graph as Graph<BaseNodeWeight, BaseEdgeWeight>>::EdgeRef: Send, EdgeWeight: Send,

§

impl<'g, BaseNodeWeight, BaseEdgeWeight, NodeWeight, EdgeWeight, Graph> Sync for FilterMap<'g, BaseNodeWeight, BaseEdgeWeight, NodeWeight, EdgeWeight, Graph>
where Graph: Sync, <Graph as Graph<BaseNodeWeight, BaseEdgeWeight>>::NodeRef: Sync, NodeWeight: Sync, <Graph as Graph<BaseNodeWeight, BaseEdgeWeight>>::EdgeRef: Sync, EdgeWeight: Sync,

§

impl<'g, BaseNodeWeight, BaseEdgeWeight, NodeWeight, EdgeWeight, Graph> Unpin for FilterMap<'g, BaseNodeWeight, BaseEdgeWeight, NodeWeight, EdgeWeight, Graph>
where <Graph as Graph<BaseNodeWeight, BaseEdgeWeight>>::NodeRef: Unpin, NodeWeight: Unpin, <Graph as Graph<BaseNodeWeight, BaseEdgeWeight>>::EdgeRef: Unpin, EdgeWeight: Unpin,

§

impl<'g, BaseNodeWeight, BaseEdgeWeight, NodeWeight, EdgeWeight, Graph> UnwindSafe for FilterMap<'g, BaseNodeWeight, BaseEdgeWeight, NodeWeight, EdgeWeight, Graph>
where Graph: RefUnwindSafe, <Graph as Graph<BaseNodeWeight, BaseEdgeWeight>>::NodeRef: UnwindSafe, NodeWeight: UnwindSafe, <Graph as Graph<BaseNodeWeight, BaseEdgeWeight>>::EdgeRef: UnwindSafe, EdgeWeight: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.