pub struct Graph {
pub nodes: BTreeMap<NodeKey, Node>,
pub edges: Vec<Edge>,
/* private fields */
}Expand description
Graph holds every node and every edge, with the edges indexed by
their endpoints.
Fields§
§nodes: BTreeMap<NodeKey, Node>The nodes, by key.
edges: Vec<Edge>The edges, sorted, without duplicates.
Implementations§
Source§impl Graph
impl Graph
Sourcepub fn new(nodes: BTreeMap<NodeKey, Node>, edges: Vec<Edge>) -> Graph
pub fn new(nodes: BTreeMap<NodeKey, Node>, edges: Vec<Edge>) -> Graph
new builds a graph from nodes and edges, and sorts the edges and
removes duplicates.
Sourcepub fn set_archived(&mut self, paths: impl IntoIterator<Item = RepoPath>)
pub fn set_archived(&mut self, paths: impl IntoIterator<Item = RepoPath>)
set_archived marks the documents at paths as archived
(CLI-7_AC-67). The call replaces the archived documents from any
earlier call.
Sourcepub fn is_archived(&self, key: &NodeKey) -> bool
pub fn is_archived(&self, key: &NodeKey) -> bool
is_archived returns whether the node at key is an archived
document.
Sourcepub fn add_key(
&mut self,
path: &RepoPath,
slug: &str,
key: &str,
line: usize,
citing: &[RepoPath],
)
pub fn add_key( &mut self, path: &RepoPath, slug: &str, key: &str, line: usize, citing: &[RepoPath], )
add_key adds a key node with a defined-in edge to its document
and a cites edge from each document in citing, and gives each
edge its inverse (CLI-7_AC-74, CLI-7_AC-75).
Sourcepub fn with_hydrator(self, hydrator: Hydrator, built: HashSet<NodeKey>) -> Graph
pub fn with_hydrator(self, hydrator: Hydrator, built: HashSet<NodeKey>) -> Graph
with_hydrator gives the graph a hydrator. The document nodes in
built already carry their fields. The hydrator reads the file of
every other document node when the node is first visited
(CACHE-1_AC-22).
Sourcepub fn hydrate(&mut self, key: &NodeKey)
pub fn hydrate(&mut self, key: &NodeKey)
hydrate reads the fields of the document node at key, and does
nothing when it has read them before or the graph has no hydrator.
Sourcepub fn kind(&self, key: &NodeKey) -> Option<NodeKind>
pub fn kind(&self, key: &NodeKey) -> Option<NodeKind>
kind returns the kind of the node at key.
Sourcepub fn edges_from(&self, key: &NodeKey) -> impl Iterator<Item = &Edge>
pub fn edges_from(&self, key: &NodeKey) -> impl Iterator<Item = &Edge>
edges_from returns the edges from key, in graph order.
Sourcepub fn edge_indices_from(&self, key: &NodeKey) -> &[usize]
pub fn edge_indices_from(&self, key: &NodeKey) -> &[usize]
edge_indices_from returns the indices of the edges from key, in
graph order.
Sourcepub fn inverse_indices(&self, edge: &Edge) -> impl Iterator<Item = usize>
pub fn inverse_indices(&self, edge: &Edge) -> impl Iterator<Item = usize>
inverse_indices returns the indices of the inverses of edge,
declared or synthesised, in graph order. An inverse is an edge with
the endpoints swapped, the same kind, region, and line, and a rel
that is the inverse of edge’s rel. inverse_indices checks the
match in both directions: the inverse of edge’s rel is the other
edge’s rel, or the inverse of the other edge’s rel is edge’s
rel. A custom rel is one that the SOKF format does not define,
and its inverse is relates-to. So a declared relates-to edge is
the inverse of every edge with a custom rel that runs in the
opposite direction between the same endpoints. An edge can have
several inverses.
Sourcepub fn parent(key: &NodeKey) -> Option<NodeKey>
pub fn parent(key: &NodeKey) -> Option<NodeKey>
parent returns the directory that contains a path node, or None
for the repository root and for a node without a path.
Sourcepub fn ensure(&mut self, path: RepoPath, kind: NodeKind)
pub fn ensure(&mut self, path: RepoPath, kind: NodeKind)
ensure gives the node at path the kind kind. The code that
resolves each START of sokf graph calls it when the START is a
directory or a repository file (CLI-7_AC-35, CLI-7_AC-37). If the
node exists, it takes the new kind and keeps its fields. If the node
doesn’t exist, ensure adds it with no fields.