Skip to main content

CsrView

Struct CsrView 

Source
pub struct CsrView<W> { /* private fields */ }
Expand description

A frozen, read-optimised copy of a graph.

§Examples

use xgraph::core::{CsrView, GraphView, ShortestPath};
use xgraph::graph::Graph;

let mut graph = Graph::<u32, &str, &str>::new(false);
let a = graph.add_node("A");
let b = graph.add_node("B");
graph.add_edge(a, b, 5, "rail").unwrap();

let frozen = CsrView::from_view(&graph);
assert_eq!(frozen.node_count(), 2);
// Algorithms are written against the abstraction, so they apply unchanged.
assert_eq!(frozen.dijkstra(a).unwrap()[&b], 5);

Implementations§

Source§

impl<W: Copy> CsrView<W>

Source

pub fn from_view<G>(source: &G) -> Self
where G: GraphView<Weight = W> + ?Sized,

Builds the projection from any view, in one pass.

The identifiers are the source graph’s own, so a route found here names nodes the original graph still recognises.

Trait Implementations§

Source§

impl<W: Clone> Clone for CsrView<W>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<W: Debug> Debug for CsrView<W>

Source§

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

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

impl<W: Copy> GraphView for CsrView<W>

Source§

type Weight = W

The type edge weights are expressed in.
Source§

type NodeIds<'a> = CsrNodeIds<'a> where Self: 'a

The iterator node_ids returns.
The iterator links returns.
Source§

fn is_directed(&self) -> bool

Whether edges are one-way.
Source§

fn node_count(&self) -> usize

The number of nodes in the graph.
Source§

fn edge_count(&self) -> usize

The number of edges in the graph, counting parallel edges separately.
Source§

fn contains_node(&self, node: NodeId) -> bool

Whether a node with this ID exists.
Source§

fn node_ids(&self) -> Self::NodeIds<'_>

Every node ID in the graph, in ascending order. Read more
Every connection leading out of node, one per incident edge. Read more
Source§

fn edge_endpoints(&self, edge: EdgeId) -> Option<(NodeId, NodeId)>

The endpoints of an edge, as stored. Read more
Source§

fn degree(&self, node: NodeId) -> usize

The number of edges incident to a node, counting parallel edges separately. Read more
Source§

fn node_id_vec(&self) -> Vec<NodeId>

Collects the node IDs into a vector. Read more

Auto Trait Implementations§

§

impl<W> Freeze for CsrView<W>
where Vec<Link<W>>: Freeze,

§

impl<W> RefUnwindSafe for CsrView<W>
where Vec<Link<W>>: RefUnwindSafe,

§

impl<W> Send for CsrView<W>
where Vec<Link<W>>: Send,

§

impl<W> Sync for CsrView<W>
where Vec<Link<W>>: Sync,

§

impl<W> Unpin for CsrView<W>
where Vec<Link<W>>: Unpin,

§

impl<W> UnsafeUnpin for CsrView<W>
where Vec<Link<W>>: UnsafeUnpin,

§

impl<W> UnwindSafe for CsrView<W>
where Vec<Link<W>>: UnwindSafe,

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<G> Bridges for G
where G: GraphView + ?Sized,

Source§

fn articulation_points(&self) -> Result<Vec<NodeId>, TraversalError>

Finds every articulation point: a node whose removal splits a component. Read more
Source§

fn bridge_edges(&self) -> Result<Vec<EdgeId>, TraversalError>

Finds every bridge, identified by edge. Read more
Source§

fn bridges(&self) -> Result<Vec<(NodeId, NodeId)>, TraversalError>

Finds every bridge, identified by its endpoints. Read more
Source§

fn tarjan_from( &self, root: NodeId, state: &mut TarjanState, ) -> Result<(), TraversalError>

Runs Tarjan’s depth-first sweep over the component containing root.
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<G> Centrality for G
where G: GraphView + ?Sized,

Source§

fn degree_centrality(&self) -> HashMap<NodeId, usize>

Degree centrality: the number of edges incident to each node. Read more
Source§

fn betweenness_centrality( &self, ) -> Result<HashMap<NodeId, f64>, CentralityError>

Betweenness centrality: how often each node lies on a shortest path between others. Read more
Source§

fn par_betweenness_centrality( &self, ) -> Result<HashMap<NodeId, f64>, CentralityError>
where Self: Sync,

Betweenness centrality, with the per-source sweeps shared across cores. Read more
Source§

fn closeness_centrality(&self) -> Result<HashMap<NodeId, f64>, CentralityError>

Closeness centrality: how near each node is to all the nodes it can reach. Read more
Source§

fn par_closeness_centrality( &self, ) -> Result<HashMap<NodeId, f64>, CentralityError>
where Self: Sync,

Closeness centrality, with the per-source sweeps shared across cores. Read more
Source§

fn eigenvector_centrality( &self, max_iter: usize, tolerance: f64, ) -> Result<HashMap<NodeId, f64>, CentralityError>
where Self::Weight: Into<f64>,

Eigenvector centrality: a node is important when its neighbours are important. Read more
Source§

fn pagerank( &self, damping: f64, max_iter: usize, tolerance: f64, ) -> Result<HashMap<NodeId, f64>, CentralityError>
where Self::Weight: Into<f64>,

PageRank: the stationary distribution of a random walk that teleports. Read more
Source§

fn katz_centrality( &self, alpha: f64, beta: f64, max_iter: usize, tolerance: f64, ) -> Result<HashMap<NodeId, f64>, CentralityError>
where Self::Weight: Into<f64>,

Katz centrality: influence that decays with distance. Read more
Source§

fn in_degree_centrality(&self) -> HashMap<NodeId, usize>

The in-degree of each node: the number of edges pointing at it. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<G> CommunityDetection for G
where G: GraphView + ?Sized,

Source§

fn detect_communities( &self, gamma: f64, ) -> Result<HashMap<usize, Vec<NodeId>>, CommunityDetectionError>
where Self::Weight: Into<f64>,

Detects communities with the given resolution and otherwise default settings. Read more
Source§

fn detect_communities_with_config( &self, config: CommunityConfig, ) -> Result<HashMap<usize, Vec<NodeId>>, CommunityDetectionError>
where Self::Weight: Into<f64>,

Detects communities with full control over the algorithm’s settings.
Source§

impl<G> Connectivity for G
where G: GraphView + ?Sized,

Source§

fn predecessors(&self) -> Predecessors

Builds the reverse adjacency of the graph. Read more
Source§

fn weakly_connected_components( &self, ) -> Result<Vec<Vec<NodeId>>, TraversalError>

Finds the weakly connected components: those of the graph with direction ignored. Read more
Source§

fn strongly_connected_components( &self, ) -> Result<Vec<Vec<NodeId>>, TraversalError>

Finds the strongly connected components using Kosaraju’s algorithm. Read more
Source§

fn connected_components(&self) -> Result<Vec<Vec<NodeId>>, TraversalError>

Finds the components appropriate to the graph’s directionality. Read more
Source§

fn is_weakly_connected(&self) -> Result<bool, TraversalError>

Whether the graph is in one piece once direction is ignored. Read more
Source§

fn is_strongly_connected(&self) -> Result<bool, TraversalError>

Whether every node can reach every other node along edge directions. Read more
Source§

fn is_connected(&self) -> Result<bool, TraversalError>

Whether the graph is connected in the sense appropriate to its directionality.
Source§

impl<G> DominatingSet for G
where G: GraphView + ?Sized,

Source§

fn dominating_set(&self) -> Result<HashSet<NodeId>, TraversalError>

Finds a dominating set greedily. Read more
Source§

fn is_dominating_set(&self, candidate: &HashSet<NodeId>) -> bool

Checks that every node is in candidate or is reached by an edge out of it. 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<G> ShortestPath for G
where G: GraphView + ?Sized,

Source§

fn dijkstra( &self, start: NodeId, ) -> Result<HashMap<NodeId, Self::Weight>, ShortestPathError>
where Self::Weight: Add<Output = Self::Weight> + PartialOrd + Default,

Shortest-path distances from start to every reachable node. Read more
Source§

fn dijkstra_with_predecessors( &self, start: NodeId, ) -> Result<(HashMap<NodeId, Self::Weight>, HashMap<NodeId, NodeId>), ShortestPathError>
where Self::Weight: Add<Output = Self::Weight> + PartialOrd + Default,

Shortest-path distances together with the predecessor tree. Read more
Source§

fn astar_path_to<H>( &self, start: NodeId, target: NodeId, heuristic: H, ) -> Result<Option<(Vec<NodeId>, Self::Weight)>, ShortestPathError>
where Self::Weight: Add<Output = Self::Weight> + PartialOrd + Default, H: Fn(NodeId) -> Self::Weight,

Finds a shortest route to one target, guided by an estimate of the distance remaining. Read more
Source§

fn shortest_path_to( &self, start: NodeId, target: NodeId, ) -> Result<Option<(Vec<NodeId>, Self::Weight)>, ShortestPathError>
where Self::Weight: Add<Output = Self::Weight> + PartialOrd + Default,

Reconstructs one shortest route between two nodes. Read more
Source§

impl<G> SpanningTree for G
where G: GraphView + ?Sized,

Source§

fn minimum_spanning_forest(&self) -> Result<Vec<EdgeId>, TraversalError>
where Self::Weight: PartialOrd,

Finds a minimum spanning forest with Kruskal’s algorithm. Read more
Source§

fn minimum_spanning_weight( &self, ) -> Result<Option<Self::Weight>, TraversalError>
where Self::Weight: PartialOrd + Add<Output = Self::Weight> + Default,

The total weight of a minimum spanning forest. Read more
Source§

impl<G> ToDot for G
where G: GraphView + ?Sized,

Source§

fn to_dot_with<S: DotStyle>(&self, name: &str, style: &S) -> String
where Self: Sized,

Renders the graph as a DOT document, using style to decide how it is drawn. Read more
Source§

fn to_dot(&self, name: &str) -> String
where Self: Sized + DotStyle,

Renders the graph as a DOT document with identifiers for labels.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<G> TopologicalSort for G
where G: GraphView + ?Sized,

Source§

fn topological_order(&self) -> Result<Vec<NodeId>, TopologicalError>

Orders the nodes so that every node precedes the nodes it points at. Read more
Source§

fn is_dag(&self) -> bool

Whether the graph is a directed acyclic graph. Read more
Source§

impl<G> Traversal for G
where G: GraphView + ?Sized,

Source§

fn explore_into( &self, start: NodeId, stop_at: Option<NodeId>, visited: &mut HashSet<NodeId>, ) -> Result<bool, TraversalError>

Explores depth-first from start, recording what it sees in visited. Read more
Source§

fn reachable_from( &self, start: NodeId, ) -> Result<HashSet<NodeId>, TraversalError>

Returns every node reachable from start, including start itself.
Source§

fn has_path( &self, start: NodeId, target: NodeId, ) -> Result<bool, TraversalError>

Checks whether any path leads from start to target. Read more
Source§

fn bfs_path( &self, start: NodeId, target: NodeId, ) -> Result<Option<Vec<NodeId>>, TraversalError>

Finds a path from start to target with the fewest edges. Read more
Source§

fn dfs_preorder_into( &self, start: NodeId, visited: &mut HashSet<NodeId>, order: &mut Vec<NodeId>, ) -> Result<(), TraversalError>

Visits every node reachable from start in depth-first pre-order. Read more
Source§

fn dfs_postorder_into( &self, start: NodeId, visited: &mut HashSet<NodeId>, order: &mut Vec<NodeId>, ) -> Result<(), TraversalError>

Visits every node reachable from start in depth-first post-order. Read more
Source§

fn has_cycle(&self) -> Result<bool, TraversalError>

Detects whether the graph contains a cycle. Read more
Source§

fn has_cycle_from( &self, root: NodeId, visited: &mut HashSet<NodeId>, ) -> Result<bool, TraversalError>

Detects a cycle in the component reachable from root. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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