Skip to main content

Graph

Struct Graph 

Source
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 list
  • rev - the reverse-oriented adjacency list
  • edges - for each EdgeId, the corresponding Edge record
  • vertices - for each VertexId, the corresponding Vertex record

§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

Source

pub fn get_edge_list( &self, edge_list_id: &EdgeListId, ) -> Result<&EdgeList, NetworkError>

access a specific EdgeList by its id

Source

pub fn n_edge_lists(&self) -> usize

Source

pub fn n_edges(&self) -> usize

number of edges in the Graph, not to be conflated with the list of edge ids

Source

pub fn n_vertices(&self) -> usize

number of vertices in the Graph

Source

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.

Source

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.

Source

pub fn edges<'a>(&'a self) -> Box<dyn Iterator<Item = &'a Edge> + 'a>

iterates through all edges in the graph

Source

pub fn get_edge( &self, edge_list_id: &EdgeListId, edge_id: &EdgeId, ) -> Result<&Edge, NetworkError>

retrieve an Edge record from the graph

§Arguments
  • edge_id - the EdgeId for the Edge that we want to retrieve
§Returns

The associated Edge or an error if the id is missing

Source

pub fn get_vertex(&self, vertex_id: &VertexId) -> Result<&Vertex, NetworkError>

retrieve a Vertex record from the graph

§Arguments
  • vertex_id - the VertexId for the Vertex that we want to retrieve
§Returns

The associated Vertex or an error if the id is missing

Source

pub fn out_edges(&self, src: &VertexId) -> Vec<(EdgeListId, EdgeId)>

retrieve a list of EdgeIds for edges that depart from the given VertexId

§Arguments
  • src - the VertexId for the source vertex of edges
§Returns

A list of EdgeIds for outbound edges that leave this VertexId, or an error if the vertex is missing from the Graph adjacency matrix.

Source

pub fn out_edges_iter<'a>( &'a self, src: &'a VertexId, ) -> Box<dyn Iterator<Item = &'a (EdgeListId, EdgeId)> + 'a>

builds an iterator

Source

pub fn in_edges(&self, dst: &VertexId) -> Vec<(EdgeListId, EdgeId)>

retrieve a list of EdgeIds for edges that arrive at the given VertexId

§Arguments
  • dst - the VertexId for the destination vertex of edges
§Returns

A list of EdgeIds for inbound edges that arrive at this VertexId, or an error if the vertex is missing from the Graph adjacency matrix.

Source

pub fn in_edges_iter<'a>( &'a self, src: &'a VertexId, ) -> Box<dyn Iterator<Item = &'a (EdgeListId, EdgeId)> + 'a>

Source

pub fn src_vertex_id( &self, edge_list_id: &EdgeListId, edge_id: &EdgeId, ) -> Result<VertexId, NetworkError>

retrieve the source vertex id of an edge

§Arguments
  • edge_id - the edge to find a source vertex id
§Returns

The source VertexId of an Edge or an error if the edge is missing

Source

pub fn dst_vertex_id( &self, edge_list_id: &EdgeListId, edge_id: &EdgeId, ) -> Result<VertexId, NetworkError>

retrieve the destination vertex id of an edge

§Arguments
  • edge_id - the edge to find a destination vertex id
§Returns

The destination VertexId of an Edge or an error if the edge is missing

Source

pub fn incident_edges( &self, vertex_id: &VertexId, direction: &Direction, ) -> Vec<(EdgeListId, EdgeId)>

helper function to give incident edges to a vertex based on a traversal direction.

§Arguments
  • vertex_id - vertex to find edges which connect to it
  • direction - whether to find out edges (Forward) or in edges (Reverse)
§Returns

The incident EdgeIds or an error if the vertex is not connected.

Source

pub fn incident_edges_iter<'a>( &'a self, vertex_id: &'a VertexId, direction: &Direction, ) -> Box<dyn Iterator<Item = &'a (EdgeListId, EdgeId)> + 'a>

helper function to give incident edges to a vertex based on a traversal direction.

§Arguments
  • vertex_id - vertex to find edges which connect to it
  • direction - whether to find out edges (Forward) or in edges (Reverse)
§Returns

The incident EdgeIds or an error if the vertex is not connected.

Source

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 it
  • direction - 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

Source

pub fn edge_triplet( &self, edge_list_id: &EdgeListId, edge_id: &EdgeId, ) -> Result<(&Vertex, &Edge, &Vertex), NetworkError>

retrieve the triplet of Vertex -> Edge -> Vertex for some EdgeId

§Arguments
  • edge_id - the id of the edge to collect attributes for
§returns

The triplet of attributes surrounding one Edge or an error if any id is invalid.

Source

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 triplets
  • direction - direction to traverse to/from the vertex_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.

Source

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 triplets
  • direction - direction to traverse to/from the vertex_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 Debug for Graph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl TryFrom<&GraphConfig> for Graph

Source§

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

The type returned in the event of a conversion error.

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

Source§

fn is_within(&self, b: &G2) -> bool