pub struct ShortestPath { /* private fields */ }Expand description
BFS-based shortest path finder.
Finds the shortest unweighted path between two nodes using breadth-first search.
§Features
- Unweighted shortest path (all edges have weight 1)
- Configurable traversal direction
- Optional edge type filtering
- Maximum depth limit for bounded searches
§Example
ⓘ
// Find shortest path between two users
let path = ShortestPath::find(&tx, user_a, user_b, Direction::Both)?;
if let Some(result) = path {
println!("Path length: {}", result.length);
println!("Path: {:?}", result.nodes);
}
// Find path following only FRIEND edges
let path = ShortestPath::new(user_a, user_b, Direction::Both)
.with_edge_type("FRIEND")
.find(&tx)?;Implementations§
Source§impl ShortestPath
impl ShortestPath
Sourcepub fn new(source: EntityId, target: EntityId, direction: Direction) -> Self
pub fn new(source: EntityId, target: EntityId, direction: Direction) -> Self
Create a new shortest path finder.
§Arguments
source- The starting nodetarget- The destination nodedirection- Which direction to traverse edges
Sourcepub const fn with_max_depth(self, max_depth: usize) -> Self
pub const fn with_max_depth(self, max_depth: usize) -> Self
Set the maximum path length to search.
If no path of this length or shorter is found, returns None.
Sourcepub fn with_edge_type(self, edge_type: impl Into<EdgeType>) -> Self
pub fn with_edge_type(self, edge_type: impl Into<EdgeType>) -> Self
Filter to only traverse edges of the specified type.
Sourcepub fn with_edge_types(
self,
edge_types: impl IntoIterator<Item = EdgeType>,
) -> Self
pub fn with_edge_types( self, edge_types: impl IntoIterator<Item = EdgeType>, ) -> Self
Filter to only traverse edges of the specified types.
Sourcepub fn exclude_nodes(self, nodes: impl IntoIterator<Item = EntityId>) -> Self
pub fn exclude_nodes(self, nodes: impl IntoIterator<Item = EntityId>) -> Self
Exclude specific nodes from the path.
Sourcepub fn find<T: Transaction>(self, tx: &T) -> GraphResult<Option<PathResult>>
pub fn find<T: Transaction>(self, tx: &T) -> GraphResult<Option<PathResult>>
Find the shortest path.
§Returns
Some(PathResult)if a path existsNoneif no path exists within the constraints
Sourcepub fn find_path<T: Transaction>(
tx: &T,
source: EntityId,
target: EntityId,
direction: Direction,
) -> GraphResult<Option<PathResult>>
pub fn find_path<T: Transaction>( tx: &T, source: EntityId, target: EntityId, direction: Direction, ) -> GraphResult<Option<PathResult>>
Convenience method: find shortest path with default settings.
§Arguments
tx- The transaction to usesource- The starting nodetarget- The destination nodedirection- Which direction to traverse
Sourcepub fn exists<T: Transaction>(self, tx: &T) -> GraphResult<bool>
pub fn exists<T: Transaction>(self, tx: &T) -> GraphResult<bool>
Check if a path exists between two nodes.
This is more efficient than find() when you only need to know
if a path exists, not what it is.
Sourcepub fn distance<T: Transaction>(self, tx: &T) -> GraphResult<Option<usize>>
pub fn distance<T: Transaction>(self, tx: &T) -> GraphResult<Option<usize>>
Find the distance between two nodes (path length).
This is more efficient than find() when you only need the distance.
Auto Trait Implementations§
impl Freeze for ShortestPath
impl RefUnwindSafe for ShortestPath
impl Send for ShortestPath
impl Sync for ShortestPath
impl Unpin for ShortestPath
impl UnsafeUnpin for ShortestPath
impl UnwindSafe for ShortestPath
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
Mutably borrows from an owned value. Read more