pub struct TopologyGraph<D> { /* private fields */ }Expand description
A TokenGraph with a lookup from a token pair to its edge.
Derefs to the graph, so the usual petgraph reads work on it directly.
Implementations§
Source§impl<D> TopologyGraph<D>
impl<D> TopologyGraph<D>
Sourcepub fn pools_between(&self, from: NodeIndex, to: NodeIndex) -> &[EdgeData<D>]
pub fn pools_between(&self, from: NodeIndex, to: NodeIndex) -> &[EdgeData<D>]
The pools trading from for to, empty if the pair is not connected.
Sourcepub fn get_token_ix(&self, token: &Address) -> Option<NodeIndex>
pub fn get_token_ix(&self, token: &Address) -> Option<NodeIndex>
The node holding token, or None if the market has no such token.
Sourcepub fn paths_between(
&self,
from: &Address,
to: &Address,
filter: &GraphQueryFilter,
) -> Result<Vec<TokenPath>, GraphError>
pub fn paths_between( &self, from: &Address, to: &Address, filter: &GraphQueryFilter, ) -> Result<Vec<TokenPath>, GraphError>
Every route between two tokens, as token sequences.
See TopologyGraph::paths_between_ix, which this resolves the addresses for.
§Errors
GraphError::TokenNotFound naming whichever of the two the market does not hold.
Sourcepub fn paths_between_ix(
&self,
from: NodeIndex,
to: NodeIndex,
filter: &GraphQueryFilter,
) -> Vec<TokenPath> ⓘ
pub fn paths_between_ix( &self, from: NodeIndex, to: NodeIndex, filter: &GraphQueryFilter, ) -> Vec<TokenPath> ⓘ
Every token path from from to to within the filter’s hop bounds.
Empty when there is no route. Check TopologyGraph::expand_path for expanded pool paths.
Routes come back shortest first. Within a length they are in no particular order.
Sourcepub fn expand_path(
&self,
token_path: &[NodeIndex],
max_paths: Option<usize>,
) -> Vec<Path<'_, D>>
pub fn expand_path( &self, token_path: &[NodeIndex], max_paths: Option<usize>, ) -> Vec<Path<'_, D>>
Writes out one route per combination of pools along token_path.
A token sequence stands for as many routes as the product of the pools on each of its legs. They are enumerated by counting: the rightmost leg advances first, and carries into the leg to its left when it wraps.
That product is unbounded — four legs of twenty pools is 160,000 routes — so max_paths
caps how many are written. The ones past the cap are dropped in counting order, which no
ranking has seen yet, so a cap trades routes the caller might have wanted for a bound on
what one sequence can allocate. None writes them all.
Methods from Deref<Target = TokenGraph<D>>§
Sourcepub fn capacity(&self) -> (usize, usize)
pub fn capacity(&self) -> (usize, usize)
Return the current node and edge capacity of the graph.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Return the number of nodes (vertices) in the graph.
Computes in O(1) time.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Return the number of edges in the graph.
Computes in O(1) time.
Sourcepub fn is_directed(&self) -> bool
pub fn is_directed(&self) -> bool
Whether the graph has directed edges or not.
pub fn contains_node(&self, a: NodeIndex<Ix>) -> bool
Sourcepub fn node_weight(&self, a: NodeIndex<Ix>) -> Option<&N>
pub fn node_weight(&self, a: NodeIndex<Ix>) -> Option<&N>
Access the weight for node a.
Also available with indexing syntax: &graph[a].
Sourcepub fn node_weights(&self) -> impl Iterator<Item = &N>
pub fn node_weights(&self) -> impl Iterator<Item = &N>
Return an iterator yielding immutable access to all node weights.
The order in which weights are yielded matches the order of their node indices.
Sourcepub fn node_indices(&self) -> NodeIndices<'_, N, Ix> ⓘ
pub fn node_indices(&self) -> NodeIndices<'_, N, Ix> ⓘ
Return an iterator over the node indices of the graph
Sourcepub fn edge_weight(&self, e: EdgeIndex<Ix>) -> Option<&E>
pub fn edge_weight(&self, e: EdgeIndex<Ix>) -> Option<&E>
Access the weight for edge e.
Also available with indexing syntax: &graph[e].
Sourcepub fn edge_weights(&self) -> impl Iterator<Item = &E>
pub fn edge_weights(&self) -> impl Iterator<Item = &E>
Return an iterator yielding immutable access to all edge weights.
The order in which weights are yielded matches the order of their edge indices.
Sourcepub fn edge_endpoints(
&self,
e: EdgeIndex<Ix>,
) -> Option<(NodeIndex<Ix>, NodeIndex<Ix>)>
pub fn edge_endpoints( &self, e: EdgeIndex<Ix>, ) -> Option<(NodeIndex<Ix>, NodeIndex<Ix>)>
Access the source and target nodes for e.
Sourcepub fn edge_indices(&self) -> EdgeIndices<'_, E, Ix> ⓘ
pub fn edge_indices(&self) -> EdgeIndices<'_, E, Ix> ⓘ
Return an iterator over the edge indices of the graph
Sourcepub fn edges_connecting(
&self,
a: NodeIndex<Ix>,
b: NodeIndex<Ix>,
) -> EdgesConnecting<'_, E, Ty, Ix> ⓘ
pub fn edges_connecting( &self, a: NodeIndex<Ix>, b: NodeIndex<Ix>, ) -> EdgesConnecting<'_, E, Ty, Ix> ⓘ
Return an iterator over all the edges connecting a and b.
Directed: Outgoing edges froma.Undirected: All edges connected toa.
Iterator element type is EdgeReference<E, Ix>.
Sourcepub fn contains_edge(&self, a: NodeIndex<Ix>, b: NodeIndex<Ix>) -> bool
pub fn contains_edge(&self, a: NodeIndex<Ix>, b: NodeIndex<Ix>) -> bool
Lookup if there is an edge from a to b.
Computes in O(e’) time, where e’ is the number of edges
connected to a (and b, if the graph edges are undirected).
Sourcepub fn find_edge(
&self,
a: NodeIndex<Ix>,
b: NodeIndex<Ix>,
) -> Option<EdgeIndex<Ix>>
pub fn find_edge( &self, a: NodeIndex<Ix>, b: NodeIndex<Ix>, ) -> Option<EdgeIndex<Ix>>
Lookup an edge from a to b.
Computes in O(e’) time, where e’ is the number of edges
connected to a (and b, if the graph edges are undirected).
Sourcepub fn find_edge_undirected(
&self,
a: NodeIndex<Ix>,
b: NodeIndex<Ix>,
) -> Option<(EdgeIndex<Ix>, Direction)>
pub fn find_edge_undirected( &self, a: NodeIndex<Ix>, b: NodeIndex<Ix>, ) -> Option<(EdgeIndex<Ix>, Direction)>
Lookup an edge between a and b, in either direction.
If the graph is undirected, then this is equivalent to .find_edge().
Return the edge index and its directionality, with Outgoing meaning
from a to b and Incoming the reverse,
or None if the edge does not exist.
Sourcepub fn neighbors(&self, a: NodeIndex<Ix>) -> Neighbors<'_, E, Ix> ⓘ
pub fn neighbors(&self, a: NodeIndex<Ix>) -> Neighbors<'_, E, Ix> ⓘ
Return an iterator of all nodes with an edge starting from a.
Directed: Outgoing edges froma.Undirected: All edges connected toa.
Produces an empty iterator if the node doesn’t exist.
Iterator element type is NodeIndex<Ix>.
Use .neighbors(a).detach() to get a neighbor walker that does
not borrow from the graph.
Sourcepub fn neighbors_directed(
&self,
a: NodeIndex<Ix>,
dir: Direction,
) -> Neighbors<'_, E, Ix> ⓘ
pub fn neighbors_directed( &self, a: NodeIndex<Ix>, dir: Direction, ) -> Neighbors<'_, E, Ix> ⓘ
Return an iterator of all neighbors that have an edge between them and a,
in the specified direction.
If the graph’s edges are undirected, this is equivalent to .neighbors(a).
Directed,Outgoing: All edges froma.Directed,Incoming: All edges toa.Undirected: All edges connected toa.
Produces an empty iterator if the node doesn’t exist.
Iterator element type is NodeIndex<Ix>.
Use .neighbors_directed(a, dir).detach() to get a neighbor walker that does
not borrow from the graph.
Sourcepub fn neighbors_undirected(&self, a: NodeIndex<Ix>) -> Neighbors<'_, E, Ix> ⓘ
pub fn neighbors_undirected(&self, a: NodeIndex<Ix>) -> Neighbors<'_, E, Ix> ⓘ
Return an iterator of all neighbors that have an edge between them and a,
in either direction.
If the graph’s edges are undirected, this is equivalent to .neighbors(a).
DirectedandUndirected: All edges connected toa.
Produces an empty iterator if the node doesn’t exist.
Iterator element type is NodeIndex<Ix>.
Use .neighbors_undirected(a).detach() to get a neighbor walker that does
not borrow from the graph.
Sourcepub fn edges(&self, a: NodeIndex<Ix>) -> Edges<'_, E, Ty, Ix> ⓘ
pub fn edges(&self, a: NodeIndex<Ix>) -> Edges<'_, E, Ty, Ix> ⓘ
Return an iterator of all edges of a.
Directed: Outgoing edges froma.Undirected: All edges connected toa.
Produces an empty iterator if the node doesn’t exist.
Iterator element type is EdgeReference<E, Ix>.
Sourcepub fn edges_directed(
&self,
a: NodeIndex<Ix>,
dir: Direction,
) -> Edges<'_, E, Ty, Ix> ⓘ
pub fn edges_directed( &self, a: NodeIndex<Ix>, dir: Direction, ) -> Edges<'_, E, Ty, Ix> ⓘ
Return an iterator of all edges of a, in the specified direction.
Directed,Outgoing: All edges froma.Directed,Incoming: All edges toa.Undirected,Outgoing: All edges connected toa, withabeing the source of each edge.Undirected,Incoming: All edges connected toa, withabeing the target of each edge.
Produces an empty iterator if the node a doesn’t exist.
Iterator element type is EdgeReference<E, Ix>.
Sourcepub fn externals(&self, dir: Direction) -> Externals<'_, N, Ty, Ix> ⓘ
pub fn externals(&self, dir: Direction) -> Externals<'_, N, Ty, Ix> ⓘ
Return an iterator over either the nodes without edges to them
(Incoming) or from them (Outgoing).
An internal node has both incoming and outgoing edges.
The nodes in .externals(Incoming) are the source nodes and
.externals(Outgoing) are the sinks of the graph.
For a graph with undirected edges, both the sinks and the sources are just the nodes without edges.
The whole iteration computes in O(|V|) time.
Sourcepub fn map<'a, F, G, N2, E2>(
&'a self,
node_map: F,
edge_map: G,
) -> StableGraph<N2, E2, Ty, Ix>
pub fn map<'a, F, G, N2, E2>( &'a self, node_map: F, edge_map: G, ) -> StableGraph<N2, E2, Ty, Ix>
Create a new StableGraph by mapping node and
edge weights to new values.
The resulting graph has the same structure and the same
graph indices as self.
Sourcepub fn filter_map<'a, F, G, N2, E2>(
&'a self,
node_map: F,
edge_map: G,
) -> StableGraph<N2, E2, Ty, Ix>
pub fn filter_map<'a, F, G, N2, E2>( &'a self, node_map: F, edge_map: G, ) -> StableGraph<N2, E2, Ty, Ix>
Create a new StableGraph by mapping nodes and edges.
A node or edge may be mapped to None to exclude it from
the resulting graph.
Nodes are mapped first with the node_map closure, then
edge_map is called for the edges that have not had any endpoint
removed.
The resulting graph has the structure of a subgraph of the original graph. Nodes and edges that are not removed maintain their old node or edge indices.
Trait Implementations§
Source§impl<D> Default for TopologyGraph<D>
impl<D> Default for TopologyGraph<D>
Source§impl<D> Deref for TopologyGraph<D>
impl<D> Deref for TopologyGraph<D>
Source§impl<D: Clone + Send + Sync> GraphManager<TopologyGraph<D>> for TopologyGraphManager<D>
impl<D: Clone + Send + Sync> GraphManager<TopologyGraph<D>> for TopologyGraphManager<D>
Source§fn initialize_graph(
&mut self,
component_topology: &FxHashMap<ComponentId, Vec<Address>>,
)
fn initialize_graph( &mut self, component_topology: &FxHashMap<ComponentId, Vec<Address>>, )
Source§fn graph(&self) -> &TopologyGraph<D>
fn graph(&self) -> &TopologyGraph<D>
Auto Trait Implementations§
impl<D> Freeze for TopologyGraph<D>
impl<D> RefUnwindSafe for TopologyGraph<D>
impl<D> Send for TopologyGraph<D>
impl<D> Sync for TopologyGraph<D>
impl<D> Unpin for TopologyGraph<D>
impl<D> UnsafeUnpin for TopologyGraph<D>
impl<D> UnwindSafe for TopologyGraph<D>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.