Quickly turn deserialized data into graphs
Quick start
Provides core traits [Identity
], [Identifiable
], [Query
] and [Edges
] as an
abstraction to traverse arbitrary data and link it up into a graph. Allows generic
traversals / multiple types of traversals through the same data.
Traits ExtractData
and node annotations allow extraction of metadata into a graph.
Single threaded (still pretty fast though).
Full example:
use *;
use fmt;
type Id = i32;
// Core traits
use ;
// For convenience this is also implemented by default for i32.
// Ids must be lightweight, comparable and cheaply cloneable.
// if you're using strings, consider using an Rc
// This trait tells the graph system that a type can be used to
// look up nodes when required
use ;
// Identifier, Node Metadata, Edge Metadata
type ItemGraph = ;
let data = ListOfItems ;
let graph = build_graph;
Adding node metadata
The [ExtractData
] trait provides a way to pull data out of a datasource and
add it to a node.
use Cow;
use *;
The extracted value must be 'static
. This is to prevent the graph grom having
live references from the source data. Source data may be dropped after the graph
has been built.
Providing multiple traversals
Multiple edge traversals may be provided using unit types as the second parameter to
[Edges
].
use *;
;
;
This allows multiple traversals to be defined when building a graph
type ItemChildGraph = ;
type ItemParentGraph = ;
Traversing the graphs
BFS and DFS traversals are provided via EdgeTraversal
. An acyclic version is in the
same module as AcyclicTraversal
.
Traversals produce TraversedNodes
and can be used to prune, or truncate existing graphs.
Annotating nodes
Sometimes during traversal we want to annotate nodes with temporary data. These annotations are preserved when truncating or pruning graphs, but may not be present for all nodes (or be consistent between traversals).
A good example of this are annotating webpack chunks onto webpack modules. The chunk that a module is found in is highly dependent on the entrypoint the traversal started from.
let node = new_default;
;
node.annotate;
node.annotate;
This relies on Any
and downcasting internally. Any type can be stored here for as long
as there is only one copy of that type.