dart-lang / tools

This repository is home to tooling related Dart packages.
BSD 3-Clause "New" or "Revised" License
28 stars 20 forks source link

Adding graph capabilities #226

Closed freemansoft closed 1 month ago

freemansoft commented 8 months ago

I was looking for a graph library for an Advent of Code problem. I ran across the graph library here and realized that I needed to be able to build graphs, and needed more algorithms. Is the tools project looking to add more graph capability? Graph capabilities are outside the normal Dart use case.

I am working on this library and am interested in contributing if there is interest and it adds value https://github.com/freemansoft/fs-dart-tools/tree/main/packages/graphs.

natebosch commented 1 month ago

We intentionally don't ship any data structures for a graph, focusing instead on algorithms across a representation agnostic interface (the callback arguments).

I think it would make sense to ship a separate package with matrix representations, and using tear-offs to easily invoke the package:graphs algorithms.

import 'package:graphs/graphs.dart';
import 'package:graph_structures/graph_structures.dart';

void main() {
  var graph = DirectedAdjacencyList<String>();
  // DirectedAdjacencyList might have an API like:
  //
  //     List<String> fooEdges = graph.edges('foo');
  //
  // Use as a tear-off for graphs APIs
  var path = shortestPath(start, target, graph.edges);
}

I'll close this issue for now since we do not plan to introduce data structures in to the graphs package.