ForceDirectedGraph<T>.generateNTree constructor

ForceDirectedGraph<T>.generateNTree({
  1. required int nodeCount,
  2. required int maxDepth,
  3. required int n,
  4. required T generator(),
  5. GraphConfig config = const GraphConfig(),
})

Generate a random tree graph. nodeCount is the max node count. maxDepth is the max depth of the tree. n is the max children count of a node. generator is the generator of the node data. Make sure the data is unique.

Implementation

ForceDirectedGraph.generateNTree({
  required int nodeCount,
  required int maxDepth,
  required int n,
  required T Function() generator,
  this.config = const GraphConfig(),
}) {
  Random random = Random();
  final root = Node(generator());
  nodes.add(root);
  _createNTree(root, nodeCount - 1, maxDepth - 1, n, random, generator);
}