Skip to main content

CsrGraph

Struct CsrGraph 

Source
pub struct CsrGraph<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
where NodeIndex: LayoutIndex, EdgeIndex: LayoutIndex, OffsetWord: LayoutWord<Index = EdgeIndex>, TargetWord: LayoutWord<Index = NodeIndex>,
{ /* private fields */ }
Expand description

Borrowed compressed-sparse-row graph view.

The graph stores outgoing adjacency using offsets[node]..offsets[node + 1] ranges into the flat targets slice. The view borrows both slices and does not allocate. NodeIndex is the host-endian logical index type used for node IDs and target entries. EdgeIndex is the host-endian logical index type used for edge IDs and offset entries. The borrowed offset and target slices may use native words or matching little-endian zerocopy words.

§Performance

Creating a validated view is O(n + m) for n nodes and m edges because validation checks monotonic offsets and target bounds. Outgoing traversal for one node is O(1) to create and O(k) to yield k outgoing edges.

Implementations§

Source§

impl<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord> CsrGraph<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
where NodeIndex: LayoutIndex, EdgeIndex: LayoutIndex, OffsetWord: LayoutWord<Index = EdgeIndex>, TargetWord: LayoutWord<Index = NodeIndex>,

Source

pub fn validate( node_count: NodeIndex, offsets: &'view [OffsetWord], targets: &'view [TargetWord], ) -> Result<Self, CsrError<NodeIndex, EdgeIndex>>

Validates borrowed CSR sections and returns a graph view.

§Errors

Returns CsrError when offsets have the wrong length, offsets are not monotonic, the final offset does not match targets.len(), a target is out of range, or an index count cannot be represented as usize on the current target.

§Performance

Validation is O(n + m) for n nodes and m edges.

Source

pub const fn offsets(&self) -> &'view [OffsetWord]

Returns the borrowed CSR offset slice.

§Performance

This method is O(1).

Source

pub const fn targets(&self) -> &'view [TargetWord]

Returns the borrowed CSR target slice.

§Performance

This method is O(1).

Source

pub fn for_each_out_target( &self, source: CsrNodeId<NodeIndex>, visit: impl FnMut(CsrNodeId<NodeIndex>) -> bool, ) -> bool

Walks outgoing target node ids for source via the CSR target slice.

Stops early when visit returns true. Returns true when stopped early.

§Performance

This method is O(k) for k outgoing edges with no iterator adapters.

Source

pub fn contains_node(&self, node: CsrNodeId<NodeIndex>) -> bool

Returns whether node is valid in this CSR view.

§Performance

This method is O(1).

Source

pub fn contains_edge(&self, edge: CsrEdgeId<EdgeIndex>) -> bool

Returns whether edge is valid in this CSR view.

§Performance

This method is O(1).

Source

pub fn try_target( &self, edge: CsrEdgeId<EdgeIndex>, ) -> Option<CsrNodeId<NodeIndex>>

Returns the target node for edge when edge is valid in this view.

§Performance

This method is O(1).

Source§

impl<'view, NodeIndex, EdgeIndex> CsrGraph<'view, NodeIndex, EdgeIndex, <EdgeIndex as SnapshotWidth>::LittleEndianWord, <NodeIndex as SnapshotWidth>::LittleEndianWord>
where NodeIndex: CsrSnapshotIndex, EdgeIndex: CsrSnapshotIndex,

Source

pub fn from_snapshot( snapshot: &Snapshot<'view>, ) -> Result<Self, CsrSnapshotError<NodeIndex, EdgeIndex>>

Builds a snapshot-backed CSR view from a validated Snapshot.

Reads the width-specific CSR offsets and targets sections, borrows them as little-endian index words, derives node_count from offsets.len() - 1, and runs CSR-shape validation. The returned view borrows directly from the snapshot’s byte slice and does not copy. Use CsrSnapshotGraph to select node and edge snapshot widths, for example CsrSnapshotGraph<'_, u32, u64>.

This delegates to from_snapshot_with_kinds using the width-default offsets/targets kinds and section version.

§Errors

Returns CsrSnapshotError when either section is missing, has the wrong version, cannot be viewed as the selected word width, is empty, has too many offsets for the selected index type, or fails CSR validation.

§Performance

This function is O(s + n + m) for s snapshot sections, n graph nodes, and m graph edges.

Source

pub fn from_snapshot_with_kinds( snapshot: &Snapshot<'view>, offsets_kind: u32, targets_kind: u32, version: u32, ) -> Result<Self, CsrSnapshotError<NodeIndex, EdgeIndex>>

Builds a snapshot-backed CSR view using caller-chosen section kinds.

Identical to from_snapshot but with the offsets and targets section kinds and the section version supplied explicitly, so storage layers that persist CSR in a non-default band (for example an inbound CSC index) can reuse the same validated borrow logic.

§Errors

Returns CsrSnapshotError when either section is missing, has the wrong version, cannot be viewed as the selected word width, is empty, has too many offsets for the selected index type, or fails CSR validation.

§Performance

This function is O(s + n + m) for s snapshot sections, n graph nodes, and m graph edges.

Trait Implementations§

Source§

impl<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord> Clone for CsrGraph<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
where NodeIndex: LayoutIndex + Clone, EdgeIndex: LayoutIndex + Clone, OffsetWord: LayoutWord<Index = EdgeIndex> + Clone, TargetWord: LayoutWord<Index = NodeIndex> + Clone,

Source§

fn clone(&self) -> CsrGraph<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord>

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<NodeIndex, EdgeIndex, OffsetWord, TargetWord> ContainsElement for CsrGraph<'_, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
where NodeIndex: LayoutIndex, EdgeIndex: LayoutIndex, OffsetWord: LayoutWord<Index = EdgeIndex>, TargetWord: LayoutWord<Index = NodeIndex>,

Source§

fn contains_element(&self, element: CsrNodeId<NodeIndex>) -> bool

Returns whether element is valid and visible in this view. Read more
Source§

impl<NodeIndex, EdgeIndex, OffsetWord, TargetWord> ContainsRelation for CsrGraph<'_, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
where NodeIndex: LayoutIndex, EdgeIndex: LayoutIndex, OffsetWord: LayoutWord<Index = EdgeIndex>, TargetWord: LayoutWord<Index = NodeIndex>,

Source§

fn contains_relation(&self, relation: CsrEdgeId<EdgeIndex>) -> bool

Returns whether relation is valid and visible in this view. Read more
Source§

impl<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord> Copy for CsrGraph<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
where NodeIndex: LayoutIndex + Copy, EdgeIndex: LayoutIndex + Copy, OffsetWord: LayoutWord<Index = EdgeIndex> + Copy, TargetWord: LayoutWord<Index = NodeIndex> + Copy,

Source§

impl<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord> Debug for CsrGraph<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
where NodeIndex: LayoutIndex + Debug, EdgeIndex: LayoutIndex + Debug, OffsetWord: LayoutWord<Index = EdgeIndex> + Debug, TargetWord: LayoutWord<Index = NodeIndex> + Debug,

Source§

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

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

impl<NodeIndex, EdgeIndex, OffsetWord, TargetWord> EdgeTargetGraph for CsrGraph<'_, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
where NodeIndex: LayoutIndex, EdgeIndex: LayoutIndex, OffsetWord: LayoutWord<Index = EdgeIndex>, TargetWord: LayoutWord<Index = NodeIndex>,

Source§

fn target(&self, edge: CsrEdgeId<EdgeIndex>) -> CsrNodeId<NodeIndex>

Returns the target node of edge. edge must be a valid edge ID.
Source§

impl<NodeIndex, EdgeIndex, OffsetWord, TargetWord> ElementIndex for CsrGraph<'_, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
where NodeIndex: LayoutIndex, EdgeIndex: LayoutIndex, OffsetWord: LayoutWord<Index = EdgeIndex>, TargetWord: LayoutWord<Index = NodeIndex>,

Source§

fn element_bound(&self) -> usize

Returns the exclusive upper bound for element indexes in this view. Read more
Source§

fn element_index(&self, element: CsrNodeId<NodeIndex>) -> usize

Returns the dense index for element in this view. Read more
Source§

impl<NodeIndex, EdgeIndex, OffsetWord, TargetWord> ElementSuccessors for CsrGraph<'_, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
where NodeIndex: LayoutIndex, EdgeIndex: LayoutIndex, OffsetWord: LayoutWord<Index = EdgeIndex>, TargetWord: LayoutWord<Index = NodeIndex>,

Source§

type Successors<'view> = IdSlice<'view, TargetWord, LocalId<NodeAxis, NodeIndex>> where Self: 'view

Iterator over successor element IDs reached from one element. Read more
Source§

fn element_successors(&self, node: CsrNodeId<NodeIndex>) -> Self::Successors<'_>

Returns elements reachable through outgoing connections from element. Read more
Source§

impl<NodeIndex, EdgeIndex, OffsetWord, TargetWord> GraphCounts for CsrGraph<'_, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
where NodeIndex: LayoutIndex, EdgeIndex: LayoutIndex, OffsetWord: LayoutWord<Index = EdgeIndex>, TargetWord: LayoutWord<Index = NodeIndex>,

Source§

fn node_count(&self) -> usize

Returns the number of nodes visible in this graph view.
Source§

fn edge_count(&self) -> usize

Returns the number of edges visible in this graph view.
Source§

impl<NodeIndex, EdgeIndex, OffsetWord, TargetWord> OutgoingEdgeCount for CsrGraph<'_, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
where NodeIndex: LayoutIndex, EdgeIndex: LayoutIndex, OffsetWord: LayoutWord<Index = EdgeIndex>, TargetWord: LayoutWord<Index = NodeIndex>,

Source§

fn out_degree(&self, node: CsrNodeId<NodeIndex>) -> usize

Returns the number of edges leaving node.
Source§

impl<NodeIndex, EdgeIndex, OffsetWord, TargetWord> OutgoingGraph for CsrGraph<'_, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
where NodeIndex: LayoutIndex, EdgeIndex: LayoutIndex, OffsetWord: LayoutWord<Index = EdgeIndex>, TargetWord: LayoutWord<Index = NodeIndex>,

Source§

type OutEdges<'view> = CsrOutEdges<EdgeIndex> where Self: 'view

Iterator over edge IDs leaving one source node.
Source§

fn outgoing_edges(&self, node: CsrNodeId<NodeIndex>) -> Self::OutEdges<'_>

Returns edges whose source is node.
Source§

impl<NodeIndex, EdgeIndex, OffsetWord, TargetWord> RelationIndex for CsrGraph<'_, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
where NodeIndex: LayoutIndex, EdgeIndex: LayoutIndex, OffsetWord: LayoutWord<Index = EdgeIndex>, TargetWord: LayoutWord<Index = NodeIndex>,

Source§

fn relation_bound(&self) -> usize

Returns the exclusive upper bound for relation indexes in this view. Read more
Source§

fn relation_index(&self, relation: CsrEdgeId<EdgeIndex>) -> usize

Returns the dense index for relation in this view. Read more
Source§

impl<NodeIndex, EdgeIndex, OffsetWord, TargetWord> TopologyBase for CsrGraph<'_, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
where NodeIndex: LayoutIndex, EdgeIndex: LayoutIndex, OffsetWord: LayoutWord<Index = EdgeIndex>, TargetWord: LayoutWord<Index = NodeIndex>,

Source§

type ElementId = LocalId<NodeAxis, NodeIndex>

Identity of a topology element. Read more
Source§

type RelationId = LocalId<EdgeAxis, EdgeIndex>

Identity of a topology relation. Read more
Source§

impl<NodeIndex, EdgeIndex, OffsetWord, TargetWord> TopologyCounts for CsrGraph<'_, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
where NodeIndex: LayoutIndex, EdgeIndex: LayoutIndex, OffsetWord: LayoutWord<Index = EdgeIndex>, TargetWord: LayoutWord<Index = NodeIndex>,

Source§

fn element_count(&self) -> usize

Returns the number of elements visible in this topology view. Read more
Source§

fn relation_count(&self) -> usize

Returns the number of relations visible in this topology view. Read more

Auto Trait Implementations§

§

impl<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord> Freeze for CsrGraph<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
where NodeIndex: Freeze,

§

impl<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord> RefUnwindSafe for CsrGraph<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
where NodeIndex: RefUnwindSafe, OffsetWord: RefUnwindSafe, TargetWord: RefUnwindSafe,

§

impl<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord> Send for CsrGraph<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
where NodeIndex: Send, OffsetWord: Sync, TargetWord: Sync,

§

impl<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord> Sync for CsrGraph<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
where NodeIndex: Sync, OffsetWord: Sync, TargetWord: Sync,

§

impl<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord> Unpin for CsrGraph<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
where NodeIndex: Unpin,

§

impl<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord> UnsafeUnpin for CsrGraph<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
where NodeIndex: UnsafeUnpin,

§

impl<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord> UnwindSafe for CsrGraph<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
where NodeIndex: UnwindSafe, OffsetWord: RefUnwindSafe, TargetWord: RefUnwindSafe,

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

Source§

fn contains_edge(&self, edge: Self::RelationId) -> bool

Returns whether edge is valid and visible in this graph view.
Source§

impl<T> ContainsNode for T
where T: ContainsElement,

Source§

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

Returns whether node is valid and visible in this graph view.
Source§

impl<T> EdgeIndex for T
where T: RelationIndex,

Source§

fn edge_bound(&self) -> usize

Returns the exclusive upper bound for edge indexes in this graph view.
Source§

fn edge_index(&self, edge: Self::RelationId) -> usize

Returns the dense index for edge in this graph view.
Source§

impl<T> ForwardGraph for T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> GraphBase for T
where T: TopologyBase,

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> NodeIndex for T
where T: ElementIndex,

Source§

fn node_bound(&self) -> usize

Returns the exclusive upper bound for node indexes in this graph view.
Source§

fn node_index(&self, node: Self::ElementId) -> usize

Returns the dense index for node in this graph view.
Source§

impl<T> OutgoingNeighborsGraph for T

Source§

type OutNeighbors<'view> = <T as ElementSuccessors>::Successors<'view> where T: 'view

Iterator over nodes directly reachable from one source node.
Source§

fn outgoing_neighbors( &self, node: <T as TopologyBase>::ElementId, ) -> <T as OutgoingNeighborsGraph>::OutNeighbors<'_>

Returns neighbor nodes reached by outgoing edges from node.
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<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.