pub struct CsrGraph<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord>where
NodeIndex: CsrIndex,
EdgeIndex: CsrIndex,
OffsetWord: CsrWord<Index = EdgeIndex>,
TargetWord: CsrWord<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>
impl<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord> CsrGraph<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
Sourcepub fn validate(
node_count: NodeIndex,
offsets: &'view [OffsetWord],
targets: &'view [TargetWord],
) -> Result<Self, CsrError<NodeIndex, EdgeIndex>>
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.
Sourcepub const fn offsets(&self) -> &'view [OffsetWord]
pub const fn offsets(&self) -> &'view [OffsetWord]
Sourcepub const fn targets(&self) -> &'view [TargetWord]
pub const fn targets(&self) -> &'view [TargetWord]
Sourcepub fn for_each_out_target(
&self,
source: CsrNodeId<NodeIndex>,
visit: impl FnMut(CsrNodeId<NodeIndex>) -> bool,
) -> bool
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.
Sourcepub fn contains_node(&self, node: CsrNodeId<NodeIndex>) -> bool
pub fn contains_node(&self, node: CsrNodeId<NodeIndex>) -> bool
Sourcepub fn contains_edge(&self, edge: CsrEdgeId<EdgeIndex>) -> bool
pub fn contains_edge(&self, edge: CsrEdgeId<EdgeIndex>) -> bool
Source§impl<'view, NodeIndex, EdgeIndex> CsrGraph<'view, NodeIndex, EdgeIndex, <EdgeIndex as CsrSnapshotIndex>::LittleEndianWord, <NodeIndex as CsrSnapshotIndex>::LittleEndianWord>where
NodeIndex: CsrSnapshotIndex,
EdgeIndex: CsrSnapshotIndex,
impl<'view, NodeIndex, EdgeIndex> CsrGraph<'view, NodeIndex, EdgeIndex, <EdgeIndex as CsrSnapshotIndex>::LittleEndianWord, <NodeIndex as CsrSnapshotIndex>::LittleEndianWord>where
NodeIndex: CsrSnapshotIndex,
EdgeIndex: CsrSnapshotIndex,
Sourcepub fn from_snapshot(
snapshot: &Snapshot<'view>,
) -> Result<Self, CsrSnapshotError<NodeIndex, EdgeIndex>>
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>.
§Errors
Returns CsrSnapshotError when either section is missing, 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>
impl<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord> Clone for CsrGraph<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
Source§impl<NodeIndex, EdgeIndex, OffsetWord, TargetWord> ContainsElement for CsrGraph<'_, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
impl<NodeIndex, EdgeIndex, OffsetWord, TargetWord> ContainsElement for CsrGraph<'_, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
Source§impl<NodeIndex, EdgeIndex, OffsetWord, TargetWord> ContainsRelation for CsrGraph<'_, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
impl<NodeIndex, EdgeIndex, OffsetWord, TargetWord> ContainsRelation for CsrGraph<'_, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
Source§impl<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord> Debug for CsrGraph<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
impl<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord> Debug for CsrGraph<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
Source§impl<NodeIndex, EdgeIndex, OffsetWord, TargetWord> EdgeTargetGraph for CsrGraph<'_, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
impl<NodeIndex, EdgeIndex, OffsetWord, TargetWord> EdgeTargetGraph for CsrGraph<'_, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
Source§impl<NodeIndex, EdgeIndex, OffsetWord, TargetWord> ElementIndex for CsrGraph<'_, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
impl<NodeIndex, EdgeIndex, OffsetWord, TargetWord> ElementIndex for CsrGraph<'_, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
Source§impl<NodeIndex, EdgeIndex, OffsetWord, TargetWord> ElementSuccessors for CsrGraph<'_, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
impl<NodeIndex, EdgeIndex, OffsetWord, TargetWord> ElementSuccessors for CsrGraph<'_, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
Source§type Successors<'view> = CsrOutNeighbors<'view, TargetWord>
where
Self: 'view
type Successors<'view> = CsrOutNeighbors<'view, TargetWord> where Self: 'view
Source§fn element_successors(&self, node: CsrNodeId<NodeIndex>) -> Self::Successors<'_>
fn element_successors(&self, node: CsrNodeId<NodeIndex>) -> Self::Successors<'_>
element. Read moreSource§impl<NodeIndex, EdgeIndex, OffsetWord, TargetWord> GraphCounts for CsrGraph<'_, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
impl<NodeIndex, EdgeIndex, OffsetWord, TargetWord> GraphCounts for CsrGraph<'_, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
Source§fn node_count(&self) -> usize
fn node_count(&self) -> usize
Source§fn edge_count(&self) -> usize
fn edge_count(&self) -> usize
Source§impl<NodeIndex, EdgeIndex, OffsetWord, TargetWord> OutgoingEdgeCount for CsrGraph<'_, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
impl<NodeIndex, EdgeIndex, OffsetWord, TargetWord> OutgoingEdgeCount for CsrGraph<'_, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
Source§fn out_degree(&self, node: CsrNodeId<NodeIndex>) -> usize
fn out_degree(&self, node: CsrNodeId<NodeIndex>) -> usize
node.Source§impl<NodeIndex, EdgeIndex, OffsetWord, TargetWord> OutgoingGraph for CsrGraph<'_, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
impl<NodeIndex, EdgeIndex, OffsetWord, TargetWord> OutgoingGraph for CsrGraph<'_, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
Source§type OutEdges<'view> = CsrOutEdges<EdgeIndex>
where
Self: 'view
type OutEdges<'view> = CsrOutEdges<EdgeIndex> where Self: 'view
Source§fn outgoing_edges(&self, node: CsrNodeId<NodeIndex>) -> Self::OutEdges<'_>
fn outgoing_edges(&self, node: CsrNodeId<NodeIndex>) -> Self::OutEdges<'_>
node.Source§impl<NodeIndex, EdgeIndex, OffsetWord, TargetWord> RelationIndex for CsrGraph<'_, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
impl<NodeIndex, EdgeIndex, OffsetWord, TargetWord> RelationIndex for CsrGraph<'_, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
Source§impl<NodeIndex, EdgeIndex, OffsetWord, TargetWord> TopologyBase for CsrGraph<'_, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
impl<NodeIndex, EdgeIndex, OffsetWord, TargetWord> TopologyBase for CsrGraph<'_, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
Source§impl<NodeIndex, EdgeIndex, OffsetWord, TargetWord> TopologyCounts for CsrGraph<'_, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
impl<NodeIndex, EdgeIndex, OffsetWord, TargetWord> TopologyCounts for CsrGraph<'_, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
Source§fn element_count(&self) -> usize
fn element_count(&self) -> usize
Source§fn relation_count(&self) -> usize
fn relation_count(&self) -> usize
impl<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord> Copy for CsrGraph<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
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>
impl<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord> Send for CsrGraph<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
impl<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord> Sync for CsrGraph<'view, NodeIndex, EdgeIndex, OffsetWord, TargetWord>
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>
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ContainsEdge for Twhere
T: ContainsRelation,
impl<T> ContainsEdge for Twhere
T: ContainsRelation,
Source§fn contains_edge(&self, edge: Self::RelationId) -> bool
fn contains_edge(&self, edge: Self::RelationId) -> bool
edge is valid and visible in this graph view.Source§impl<T> ContainsNode for Twhere
T: ContainsElement,
impl<T> ContainsNode for Twhere
T: ContainsElement,
Source§fn contains_node(&self, node: Self::ElementId) -> bool
fn contains_node(&self, node: Self::ElementId) -> bool
node is valid and visible in this graph view.Source§impl<T> EdgeIndex for Twhere
T: RelationIndex,
impl<T> EdgeIndex for Twhere
T: RelationIndex,
Source§fn edge_bound(&self) -> usize
fn edge_bound(&self) -> usize
Source§fn edge_index(&self, edge: Self::RelationId) -> usize
fn edge_index(&self, edge: Self::RelationId) -> usize
edge in this graph view.Source§impl<T> NodeIndex for Twhere
T: ElementIndex,
impl<T> NodeIndex for Twhere
T: ElementIndex,
Source§fn node_bound(&self) -> usize
fn node_bound(&self) -> usize
Source§fn node_index(&self, node: Self::ElementId) -> usize
fn node_index(&self, node: Self::ElementId) -> usize
node in this graph view.Source§impl<T> OutgoingNeighborsGraph for Twhere
T: ElementSuccessors,
impl<T> OutgoingNeighborsGraph for Twhere
T: ElementSuccessors,
Source§type OutNeighbors<'view> = <T as ElementSuccessors>::Successors<'view>
where
T: 'view
type OutNeighbors<'view> = <T as ElementSuccessors>::Successors<'view> where T: 'view
Source§fn outgoing_neighbors(
&self,
node: <T as TopologyBase>::ElementId,
) -> <T as OutgoingNeighborsGraph>::OutNeighbors<'_>
fn outgoing_neighbors( &self, node: <T as TopologyBase>::ElementId, ) -> <T as OutgoingNeighborsGraph>::OutNeighbors<'_>
node.