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>
impl<'g, BaseNodeWeight, BaseEdgeWeight, NodeWeight, EdgeWeight, Graph: Graph<BaseNodeWeight, BaseEdgeWeight>> FilterMap<'g, BaseNodeWeight, BaseEdgeWeight, NodeWeight, EdgeWeight, Graph>
Sourcepub fn new(
base_graph: &'g Graph,
node_map: HashMap<Graph::NodeRef, NodeWeight>,
edge_map: HashMap<Graph::EdgeRef, EdgeWeight>,
) -> Self
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.
Sourcepub fn general_filter_map<NodeFn, EdgeFn>(
base_graph: &'g Graph,
node_fn: NodeFn,
edge_fn: EdgeFn,
) -> Self
pub fn general_filter_map<NodeFn, EdgeFn>( base_graph: &'g Graph, node_fn: NodeFn, edge_fn: EdgeFn, ) -> Self
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.
Sourcepub fn weight_filter_map<NodeFn, EdgeFn>(
base_graph: &'g Graph,
node_fn: NodeFn,
edge_fn: EdgeFn,
) -> Selfwhere
NodeFn: Fn(&'g BaseNodeWeight) -> Option<NodeWeight>,
EdgeFn: Fn(&'g BaseEdgeWeight) -> Option<EdgeWeight>,
BaseNodeWeight: 'g,
BaseEdgeWeight: 'g,
pub fn weight_filter_map<NodeFn, EdgeFn>(
base_graph: &'g Graph,
node_fn: NodeFn,
edge_fn: EdgeFn,
) -> Selfwhere
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.
Sourcepub fn weight_map<NodeFn, EdgeFn>(
base_graph: &'g Graph,
node_fn: NodeFn,
edge_fn: EdgeFn,
) -> Selfwhere
NodeFn: Fn(&'g BaseNodeWeight) -> NodeWeight,
EdgeFn: Fn(&'g BaseEdgeWeight) -> EdgeWeight,
BaseNodeWeight: 'g,
BaseEdgeWeight: 'g,
pub fn weight_map<NodeFn, EdgeFn>(
base_graph: &'g Graph,
node_fn: NodeFn,
edge_fn: EdgeFn,
) -> Selfwhere
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>
impl<'g, NodeWeight, EdgeWeight, Graph: Graph<NodeWeight, EdgeWeight>> FilterMap<'g, NodeWeight, EdgeWeight, &'g NodeWeight, &'g EdgeWeight, Graph>
Sourcepub fn weight_filter<NodeFn, EdgeFn>(
base_graph: &'g Graph,
node_fn: NodeFn,
edge_fn: EdgeFn,
) -> Selfwhere
NodeFn: Fn(&'g NodeWeight) -> bool,
EdgeFn: Fn(&'g EdgeWeight) -> bool,
NodeWeight: 'g,
EdgeWeight: 'g,
pub fn weight_filter<NodeFn, EdgeFn>(
base_graph: &'g Graph,
node_fn: NodeFn,
edge_fn: EdgeFn,
) -> Selfwhere
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.