Skip to content

Commit 72974f2

Browse files
authored
Use HashMap/HashSet for stronglyConnectedComponents (#26)
Looks like ~10% improvement with dart2js and a ~8% improvement on VM Fixes dart-archive/graphs#25
1 parent 690e451 commit 72974f2

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

pkgs/graphs/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 0.1.3
2+
3+
- Use `HashMap` and `HashSet` from `dart:collection` for
4+
`stronglyConnectedComponents`. Improves runtime performance.
5+
16
# 0.1.2+1
27

38
- Allow using non-dev Dart 2 SDK.

pkgs/graphs/lib/src/strongly_connected_components.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ import 'dart:math' show min;
2626
List<List<V>> stronglyConnectedComponents<K, V>(
2727
Iterable<V> nodes, K Function(V) key, Iterable<V> Function(V) children) {
2828
final result = <List<V>>[];
29-
final lowLinks = <K, int>{};
30-
final indexes = <K, int>{};
31-
final onStack = Set<K>();
29+
final lowLinks = HashMap<K, int>();
30+
final indexes = HashMap<K, int>();
31+
final onStack = HashSet<K>();
3232

3333
var index = 0;
3434
var lastVisited = Queue<V>();

0 commit comments

Comments
 (0)