rustc_data_structures::graph::linked_graph - Rust (original) (raw)

Module linked_graph

Source

Expand description

See LinkedGraph.

§Interface details

You customize the graph by specifying a “node data” type N and an “edge data” type E. You can then later gain access (mutable or immutable) to these “user-data” bits. Currently, you can only add nodes or edges to the graph. You cannot remove or modify them once added. This could be changed if we have a need.

§Implementation details

The main tricky thing about this code is the way that edges are stored. The edges are stored in a central array, but they are also threaded onto two linked lists for each node, one for incoming edges and one for outgoing edges. Note that every edge is a member of some incoming list and some outgoing list. Basically you can load the first index of the linked list from the node data structures (the field first_edge) and then, for each edge, load the next index from the field next_edge). Each of those fields is an array that should be indexed by the direction (see the type Direction).

AdjacentEdges

DepthFirstTraversal

Direction

Edge

EdgeIndex

LinkedGraph

A concrete graph implementation that supports:

Node

NodeIndex

INCOMING

INVALID_EDGE_INDEX

OUTGOING