pub struct Graph {
pub vertices: Box<[Vertex]>,
pub edge_lists: Vec<EdgeList>,
pub adj: Box<[IndexMap<(EdgeListId, EdgeId), VertexId>]>,
pub rev: Box<[IndexMap<(EdgeListId, EdgeId), VertexId>]>,
}Expand description
Road network topology represented as an adjacency list.
The EdgeId and VertexId values correspond to edge and
vertex indices in the edges and vertices vectors.
§Arguments
adj- the forward-oriented adjacency listrev- the reverse-oriented adjacency listedges- for eachEdgeId, the correspondingEdgerecordvertices- for eachVertexId, the correspondingVertexrecord
§Performance
Methods provided via the Graph type prefer avoiding copies.
Operations on a single entity should be O(1). Most methods returning
collections will prefer chained iterators. A few will collect
into Vecs because of error handling or lifetimes, but those cases will only produce a
smaller subset of the source data.
Fields§
§vertices: Box<[Vertex]>§edge_lists: Vec<EdgeList>§adj: Box<[IndexMap<(EdgeListId, EdgeId), VertexId>]>§rev: Box<[IndexMap<(EdgeListId, EdgeId), VertexId>]>Implementations§
Source§impl Graph
impl Graph
Sourcepub fn get_edge_list(
&self,
edge_list_id: &EdgeListId,
) -> Result<&EdgeList, NetworkError>
pub fn get_edge_list( &self, edge_list_id: &EdgeListId, ) -> Result<&EdgeList, NetworkError>
access a specific EdgeList by its id
pub fn n_edge_lists(&self) -> usize
Sourcepub fn n_edges(&self) -> usize
pub fn n_edges(&self) -> usize
number of edges in the Graph, not to be conflated with the list of edge ids
Sourcepub fn n_vertices(&self) -> usize
pub fn n_vertices(&self) -> usize
number of vertices in the Graph
Sourcepub fn edge_ids(
&self,
edge_list_id: &EdgeListId,
) -> Result<Box<dyn Iterator<Item = EdgeId>>, NetworkError>
pub fn edge_ids( &self, edge_list_id: &EdgeListId, ) -> Result<Box<dyn Iterator<Item = EdgeId>>, NetworkError>
helper function for creating a range of all edge ids in the graph. uses the knowledge that all ids are unique and consecutive integers beginning at zero.
Sourcepub fn vertex_ids(&self) -> Box<dyn Iterator<Item = VertexId>>
pub fn vertex_ids(&self) -> Box<dyn Iterator<Item = VertexId>>
helper function for creating a range of all vertex ids in the graph. uses the knowledge that all ids are unique and consecutive integers beginning at zero.
Sourcepub fn edges<'a>(&'a self) -> Box<dyn Iterator<Item = &'a Edge> + 'a>
pub fn edges<'a>(&'a self) -> Box<dyn Iterator<Item = &'a Edge> + 'a>
iterates through all edges in the graph
Sourcepub fn get_edge(
&self,
edge_list_id: &EdgeListId,
edge_id: &EdgeId,
) -> Result<&Edge, NetworkError>
pub fn get_edge( &self, edge_list_id: &EdgeListId, edge_id: &EdgeId, ) -> Result<&Edge, NetworkError>
Sourcepub fn get_vertex(&self, vertex_id: &VertexId) -> Result<&Vertex, NetworkError>
pub fn get_vertex(&self, vertex_id: &VertexId) -> Result<&Vertex, NetworkError>
Sourcepub fn out_edges_iter<'a>(
&'a self,
src: &'a VertexId,
) -> Box<dyn Iterator<Item = &'a (EdgeListId, EdgeId)> + 'a>
pub fn out_edges_iter<'a>( &'a self, src: &'a VertexId, ) -> Box<dyn Iterator<Item = &'a (EdgeListId, EdgeId)> + 'a>
builds an iterator
pub fn in_edges_iter<'a>( &'a self, src: &'a VertexId, ) -> Box<dyn Iterator<Item = &'a (EdgeListId, EdgeId)> + 'a>
Sourcepub fn src_vertex_id(
&self,
edge_list_id: &EdgeListId,
edge_id: &EdgeId,
) -> Result<VertexId, NetworkError>
pub fn src_vertex_id( &self, edge_list_id: &EdgeListId, edge_id: &EdgeId, ) -> Result<VertexId, NetworkError>
Sourcepub fn dst_vertex_id(
&self,
edge_list_id: &EdgeListId,
edge_id: &EdgeId,
) -> Result<VertexId, NetworkError>
pub fn dst_vertex_id( &self, edge_list_id: &EdgeListId, edge_id: &EdgeId, ) -> Result<VertexId, NetworkError>
Sourcepub fn incident_edges(
&self,
vertex_id: &VertexId,
direction: &Direction,
) -> Vec<(EdgeListId, EdgeId)>
pub fn incident_edges( &self, vertex_id: &VertexId, direction: &Direction, ) -> Vec<(EdgeListId, EdgeId)>
Sourcepub fn incident_edges_iter<'a>(
&'a self,
vertex_id: &'a VertexId,
direction: &Direction,
) -> Box<dyn Iterator<Item = &'a (EdgeListId, EdgeId)> + 'a>
pub fn incident_edges_iter<'a>( &'a self, vertex_id: &'a VertexId, direction: &Direction, ) -> Box<dyn Iterator<Item = &'a (EdgeListId, EdgeId)> + 'a>
Sourcepub fn incident_vertex(
&self,
edge_list_id: &EdgeListId,
edge_id: &EdgeId,
direction: &Direction,
) -> Result<VertexId, NetworkError>
pub fn incident_vertex( &self, edge_list_id: &EdgeListId, edge_id: &EdgeId, direction: &Direction, ) -> Result<VertexId, NetworkError>
helper function to give the incident vertex to an edge based on a traversal direction.
§Arguments
edge_id- edge to find the vertex which connects to itdirection- whether to find the destination (Forward) or source (Reverse) vertex
§Returns
The incident VertexId of an edge or an error if the edge is missing
Sourcepub fn edge_triplet(
&self,
edge_list_id: &EdgeListId,
edge_id: &EdgeId,
) -> Result<(&Vertex, &Edge, &Vertex), NetworkError>
pub fn edge_triplet( &self, edge_list_id: &EdgeListId, edge_id: &EdgeId, ) -> Result<(&Vertex, &Edge, &Vertex), NetworkError>
Sourcepub fn incident_triplet_ids(
&self,
vertex_id: &VertexId,
direction: &Direction,
) -> Result<Vec<(VertexId, EdgeListId, EdgeId, VertexId)>, NetworkError>
pub fn incident_triplet_ids( &self, vertex_id: &VertexId, direction: &Direction, ) -> Result<Vec<(VertexId, EdgeListId, EdgeId, VertexId)>, NetworkError>
creates VertexId -> EdgeId -> VertexId triplets based on
a VertexId and a traversal Direction.
Regardless of the direction chosen, the source VertexId appears first and the
terminal VertexId appears in the third slot.
§Arguments
vertex_id- id of the vertex to lookup incident tripletsdirection- direction to traverse to/from thevertex_id
§Returns
For each edge connected to this vertex_id traversable via the provided direction,
a triplet of the EdgeId and it’s connecting VertexIds.
Sourcepub fn incident_triplet_attributes(
&self,
vertex_id: &VertexId,
direction: &Direction,
) -> Result<Vec<(&Vertex, &Edge, &Vertex)>, NetworkError>
pub fn incident_triplet_attributes( &self, vertex_id: &VertexId, direction: &Direction, ) -> Result<Vec<(&Vertex, &Edge, &Vertex)>, NetworkError>
creates Vertex -> Edge -> Vertex triplets based on
a Vertex and a traversal Direction.
Regardless of the direction chosen, the source Vertex appears first and the
terminal Vertex appears in the third slot.
§Arguments
vertex_id- id of the vertex to lookup incident tripletsdirection- direction to traverse to/from thevertex_id
§Returns
For each edge connected to this vertex_id traversable via the provided direction,
a triplet of the Edge and it’s connecting Vertexs.
Trait Implementations§
Source§impl TryFrom<&GraphConfig> for Graph
impl TryFrom<&GraphConfig> for Graph
Source§fn try_from(config: &GraphConfig) -> Result<Self, Self::Error>
fn try_from(config: &GraphConfig) -> Result<Self, Self::Error>
create a graph from a JSON argument. it should be an object that contains two keys, one for each file path.
Source§type Error = NetworkError
type Error = NetworkError
Auto Trait Implementations§
impl Freeze for Graph
impl RefUnwindSafe for Graph
impl Send for Graph
impl Sync for Graph
impl Unpin for Graph
impl UnsafeUnpin for Graph
impl UnwindSafe for Graph
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
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 more