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>,
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>,
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 SnapshotWidth>::LittleEndianWord, <NodeIndex as SnapshotWidth>::LittleEndianWord>where
NodeIndex: CsrSnapshotIndex,
EdgeIndex: CsrSnapshotIndex,
impl<'view, NodeIndex, EdgeIndex> CsrGraph<'view, NodeIndex, EdgeIndex, <EdgeIndex as SnapshotWidth>::LittleEndianWord, <NodeIndex as SnapshotWidth>::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>.
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.
Sourcepub fn from_snapshot_with_kinds(
snapshot: &Snapshot<'view>,
offsets_kind: u32,
targets_kind: u32,
version: u32,
) -> Result<Self, CsrSnapshotError<NodeIndex, EdgeIndex>>
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,
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§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>,
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§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>,
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§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,
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§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>,
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§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>,
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§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>,
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
type Successors<'view> = IdSlice<'view, TargetWord, LocalId<NodeAxis, NodeIndex>> 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>where
NodeIndex: LayoutIndex,
EdgeIndex: LayoutIndex,
OffsetWord: LayoutWord<Index = EdgeIndex>,
TargetWord: LayoutWord<Index = NodeIndex>,
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
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>where
NodeIndex: LayoutIndex,
EdgeIndex: LayoutIndex,
OffsetWord: LayoutWord<Index = EdgeIndex>,
TargetWord: LayoutWord<Index = NodeIndex>,
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
fn out_degree(&self, node: CsrNodeId<NodeIndex>) -> usize
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>,
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
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>where
NodeIndex: LayoutIndex,
EdgeIndex: LayoutIndex,
OffsetWord: LayoutWord<Index = EdgeIndex>,
TargetWord: LayoutWord<Index = NodeIndex>,
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§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>,
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§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>,
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
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>where
NodeIndex: LayoutIndex + Copy,
EdgeIndex: LayoutIndex + Copy,
OffsetWord: LayoutWord<Index = EdgeIndex> + Copy,
TargetWord: LayoutWord<Index = NodeIndex> + Copy,
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.