graphs 0.1.2+1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 73

Build Status

Graph algorithms which do not specify a particular approach for representing a Graph.

Functions in this package will take arguments that provide the mechanism for traversing the graph. For example two common approaches for representing a graph:

class Graph {
  Map<Node, List<Node>> nodes;
}
class Node {
  // Interesting data
}
class Graph {
  Node root;
}
class Node {
  List<Node> children;
  // Interesting data
}

Any representation can be adapted to the needs of the algorithm:

  • Some algorithms need to associate data with each node in the graph and it will be keyed by some type K that must work as a key in a HashMap. If nodes implement hashCode and ==, or if they are known to have one instance per logical node such that instance equality is sufficient, then the node can be passed through directly.
    • (node) => node
    • (node) => node.id
  • Algorithms which need to traverse the graph take a children function which provides the reachable nodes.
    • (node) => graph[node]
    • (node) => node.children

Graphs which are resolved asynchronously will have similar functions which return FutureOr.

0.1.2+1

  • Allow using non-dev Dart 2 SDK.

0.1.2

  • crawlAsync surfaces exceptions while crawling through the result stream rather than as uncaught asynchronous errors.

0.1.1

  • crawlAsync will now ignore nodes that are resolved to null.

0.1.0

  • Initial release with an implementation of stronglyConnectedComponents and crawlAsync.

example/example.dart

// Copyright (c) 2017, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:graphs/graphs.dart';

/// A representation of a directed graph.
///
/// Data is stored on the [Node] class.
class Graph {
  final Map<Node, List<Node>> nodes;
  Graph(this.nodes);
}

class Node {
  final String id;
  final int data;

  Node(this.id, this.data);

  @override
  bool operator ==(Object other) => other is Node && other.id == id;

  @override
  int get hashCode => id.hashCode;

  @override
  String toString() => '<$id -> $data>';
}

void main() {
  var nodeA = new Node('A', 1);
  var nodeB = new Node('B', 2);
  var nodeC = new Node('C', 3);
  var nodeD = new Node('D', 4);
  var graph = new Graph({
    nodeA: [nodeB, nodeC],
    nodeB: [nodeC, nodeD],
    nodeC: [nodeB, nodeD]
  });

  var components = stronglyConnectedComponents<Node, Node>(
      graph.nodes.keys, (node) => node, (node) => graph.nodes[node]);

  print(components);
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  graphs: ^0.1.2+1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:graphs/graphs.dart';
  
Version Uploaded Documentation Archive
0.1.2+1 Jul 18, 2018 Go to the documentation of graphs 0.1.2+1 Download graphs 0.1.2+1 archive
0.1.2 Apr 23, 2018 Go to the documentation of graphs 0.1.2 Download graphs 0.1.2 archive
0.1.1 Apr 18, 2018 Go to the documentation of graphs 0.1.1 Download graphs 0.1.1 archive
0.1.0 Dec 7, 2017 Go to the documentation of graphs 0.1.0 Download graphs 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
54
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
73
Learn more about scoring.

We analyzed this package on Oct 10, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.4

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:graphs/graphs.dart.

Maintenance suggestions

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.48.0 <3.0.0
Dev dependencies
analyzer ^0.32.0
path ^1.1.0
test ^0.12.0