Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- GraphNode class
- -- ModuleScript inside Graph ModuleScript
- -- by Ozzypig (Twitter: @Ozzypig, ozzypig.com)
- local GraphEdge = require(script.Parent:WaitForChild("GraphEdge"))
- local GraphNode = {}
- GraphNode.__index = GraphNode
- function GraphNode.new(value)
- local self = setmetatable({
- value = value or 1;
- edges = {};
- }, GraphNode)
- return self
- end
- function GraphNode:eachEdge()
- return pairs(self.edges)
- end
- function GraphNode:addEdge(edge)
- self.edges[edge] = edge.value
- end
- function GraphNode:newEdgeTo(nodeTarget, ...)
- local edge = GraphEdge.new(self, nodeTarget, ...)
- self:addEdge(edge)
- return edge
- end
- return GraphNode
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement