DAG is the acronym for Directed Acyclic Graph which is basically a graph without closed loops made of 'single way' directed connections. It has a lot of pratical applications, usually related to shortest-path or topological ordering.
While the basic algorithms and the same SwiftDAG is modelled to provide a simple interface to represent data structure relations in memory, where each Node (or vertex) is an object and each Edge (or connection) is a relation between nodes.
Example:
class UFrame: Node {
var size: CGRect?
var origin: CGPoint?
}
class UView: Node {
lazy var subviews = EdgeArray<UView>(parent: self)
lazy var frame = Edge<UFrame>(parent: self)
var backgroundColor = UIColor.black
}UView is connected to UFrame via the Edge variable frame and to multiple subviews via the EdgeArray variable subviews.
The connections are created ar run-time.
Example, explicit:
let view = UView()
let frame = UFrame()
view.frame.connect(to: frame)Example, operator:
let view = UView()
let frame = UFrame()
view.frame <= framePratically speaking the base Node class contains the list of connetions and the Edge classes helps to link/unlink the Nodes
By storing the conections from a Node to its siblings it's possible to traverse the tree to create a Topological Order
print(view.topologicalOrder())
[UFrame(uuid: 140418024708768), UView(uuid: 140418022602544)]- try/catch: exceptions are used to avoid closed loops and integrity checks
- behind the scens, inner links and outer links
- direct graph manipulation
- simple queries
- serialization/deserialization
- PRO users: sourcery based API
- Integration with CocoaPods / Carthage
JSONserialization/deserialization using thehash- more examples and more tests
- travis integration
./Sourcery --templates SwiftDAG/Templates --sources . --output SwiftDAGTests --watch --verbose