toJSON method

Map<String, dynamic> toJSON()

Transforms this instance into a JSON object.

Implementation

Map<String,dynamic> toJSON() {
	final Map<String,dynamic> json = {
		'type': runtimeType.toString(),
		'digraph': digraph
	};

	final edges = [];
	final nodes = [];

	for (final ent in _nodes.entries ) {
      final key = ent.key;
      final value = ent.value;
		final adjacencyList = <Edge>[];
		getEdgesOfNode( key, adjacencyList );

		for ( int i = 0, l = adjacencyList.length; i < l; i ++ ) {
			edges.add( adjacencyList[ i ].toJSON() );
		}

		nodes.add( value.toJSON() );
	}

	json['_edges'] = edges;
	json['_nodes'] = nodes;

	return json;
}