Skip to content
This repository has been archived by the owner on Feb 6, 2022. It is now read-only.
/ Edgy Public archive

Swift value-semantic graph modeling values connected by bidirectional edges

License

Notifications You must be signed in to change notification settings

JadenGeller/Edgy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Edgy

Edgy provides a bidirectional value-semantic Graph type that can be used to form arbitrary graphs containing hashable nodes. Any Hashable type can be used as a node, such as an Int or a String. If two nodes have identity equality, then they represent the same exact node.

var codeGraph = Graph(nodes: ["Swift", "Haskell", "Rust", "C", "C++", "Objective-C", "Ruby"])
codeGraph.addEdge("Swift", "Haskell")
codeGraph.addEdge("Swift", "Objective-C")
codeGraph.addEdge("C", "Objective-C")
codeGraph.addEdge("C++", "C")
codeGraph.addEdge("C++", "Rust")

If you do desire to create multiple nodes storing the same value but with different identity, use the UniqueNode wrapper type which uses class identity.

let (a, b, c) = (UniqueNode(1), UniqueNode(1), UniqueNode(2))
var testGraph = Graph(nodes: [a, b, c])
testGraph.addEdge(b, c)
print(testGraph.connectedComponents.count) // -> 2 (since a & b are distinct nodes)

Traverse the object graph by following adjacent nodes.

for node in codeGraph.adjacentNodes("Swift") {
  print(node + " is pretty similiar to Swift")
}

About

Swift value-semantic graph modeling values connected by bidirectional edges

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages