Meld/Merge
Every StenoGraph starts out as a a vector of Edge
s. Key part of building a graph from this vector is homogenize the nodes and edges from this vector. This homogenization is driven by the two functions meld
and merge
:
StenoGraphs.meld
— Functionmeld(x)
Meldes a vector of edge/node. That means it tries to merge
elements of the vector that relate to the same nodes.
Example
# `StenoGraphs` does not implement any `EdgeModifier`s
struct Weight{N <: Number} <: EdgeModifier w::N end;
e1 = Edge(Node(:a), Node(:b));
e2 = e1 * Weight(1.0);
e3 = UndirectedEdge(Node(:a), Node(:c));
e4 = UndirectedEdge(Node(:c), Node(:a));
es = [e1, e1, e2, e2, e3, e3, e4, e4]
meld(es) == [e2, e3]
# output
true
Base.merge
— Functionmerge(x, y)
Merges two (or more) edge/node and fails if not mergable. In contrast to meld
, it returns always one edge/node or fails. Works for:
* ModifiedEdge
* ModifyingNode
* ModifiedNode
* DirectedEdge
* UndirectedEdge
* some combinations thereof (those that are mergable)
Requires carefull implementation by subtypes. Will unlikely work as expected out of the box for other subtypes because it is unclear what is mergable.
Example
# `StenoGraphs` does not implement any `EdgeModifier`s
julia> struct Weight{N <: Number} <: EdgeModifier w::N end
julia> merge(Edge(Node(:a), Node(:b)), Edge(Node(:a), Node(:b) * Weight(2)))
a → b * Weight{Int64}(2)