Graph class

Class representing a sparse graph implementation based on adjacency lists. A sparse graph can be used to model many different types of graphs like navigation graphs (pathfinding), dependency graphs (e.g. technology trees) or state graphs (a representation of every possible state in a game).

@author {@link https://github.com/Mugen87|Mugen87}

Constructors

Graph()

Properties

digraph bool
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addEdge(Edge edge) Graph
Adds an edge to the graph. If the graph is undirected, the method automatically creates the opponent edge.
addNode(Node node) Graph
Adds a node to the graph.
clear() Graph
Removes all nodes and edges from this graph.
fromJSON(Map<String, dynamic> json) Graph
Restores this instance from the given JSON object.
getEdge(int from, int to) Edge?
Returns an edge for the given from and to node indices. If no node is found, null is returned.
getEdgeCount() int
Returns the edge count of the graph.
getEdgesOfNode(int index, List<Edge> result) List<Edge>
Gathers all edges leading from the given node index and stores them into the given array.
getNode(int index) Node?
Returns a node for the given node index. If no node is found, null is returned.
getNodeCount() int
/ Returns the node count of the graph.
getNodes(List<Node> result) List<Node>
Gathers all nodes of the graph and stores them into the given array.
hasEdge(int from, int to) bool
Return true if the graph has an edge connecting the given from and to node indices.
hasNode(int index) bool
Return true if the graph has the given node index.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeEdge(Edge edge) Graph
Removes the given edge from the graph. If the graph is undirected, the method also removes the opponent edge.
removeNode(Node node) Graph
Removes the given node from the graph and all edges which are connected with this node.
toJSON() Map<String, dynamic>
Transforms this instance into a JSON object.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited