This is a library to create / change / serialize / deserialize generic graphs
To take a look at it's functionality just run the main.rs
file that contains a basic demo.
node.rs
: Functionality of each node of the graph. It is important to mention that node has a generic value.graph.rs
: Functionality of a graph of nodes. Allows for adding, changing, deleting nodes and edges between the nodes.iterator.rs
: Functionality of iterator of a graph. Implements Breadth-First Search and a Depth-First Search algorithms.handler.rs
: Functionality of serializing and deserializing the graph. Allows to write the graph into the file and create a new graph from the given file.lib.rs
: Exports all above. Contains Unit-tests.
-
Serialization is done with Trivial Graph Format
(bold characters are written into the file)
1 Root (index of a node and a label telling that this is a root)
2 (index of a node)
3 (index of a node)
4 (index of a node)
'#' (delimeter between section of nodes and edges)
1 2 (indexes of nodes that have an edge between them)
1 3 (indexes of nodes that have an edge between them)
3 4 (indexes of nodes that have an edge between them) -
Deserialization is done with the same format. But there are some things to notice here as well.
There are many modifications of a TGF and some of them regard the labels (text after the index of a node) as a value of a node. But this library is intended to provide functionality for the generic graph. That is, the node can have value of any type (that implements theDefault
trait). But I haven't yet found a universal way to serialize any provided type into TGF string the way that after parsing a string representation of a node value from the file the compiler would know what specific type a value should have.
That means:- Only nodes' indexes and edges are written into the file and read from the file.
- The only label that has any effect is a
Root
label that indicates which node is the root of the graph. Any other labels are ignored.
- Create an empty graph with
Graph::new()
. Please, make sure to specify graph's type in order for the program to work - Add nodes with given values and/or connected nodes
OR
Deserialize nodes from the TGF file withHandler::deserialize()
. Nodes will be added to the graph and edges between them will be created. But in this case you have to set each node's value after deserialization. - Add edges (if you haven't connected any nodes on the previous step)
- Set the root of the graph. Root is the node to start a graph traversal with
- Change node values / change edges / print the graph etc.
- Serialize the graph into the file (Warning all node values will be lost!)