Skip to content

Commit 6cf9507

Browse files
committed
Format.
1 parent 44e37e4 commit 6cf9507

16 files changed

Lines changed: 330 additions & 324 deletions

benchmark/directed_graph_benchmark.dart

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
import 'package:benchmark_runner/benchmark_runner.dart';
22
import 'package:directed_graph/directed_graph.dart';
33

4-
int comparator(
5-
String s1,
6-
String s2,
7-
) {
4+
int comparator(String s1, String s2) {
85
return s1.compareTo(s2);
96
}
107

11-
int inverseComparator(
12-
String s1,
13-
String s2,
14-
) {
8+
int inverseComparator(String s1, String s2) {
159
return -s1.compareTo(s2);
1610
}
1711

@@ -41,19 +35,16 @@ var l = 'l';
4135
// );
4236

4337
void main() {
44-
var graph = DirectedGraph<String>(
45-
{
46-
a: {b, h, c, e},
47-
d: {e, f},
48-
b: {h},
49-
c: {h, g},
50-
f: {i},
51-
i: {l},
52-
// h: {a},
53-
k: {g, f}
54-
},
55-
comparator: comparator,
56-
);
38+
var graph = DirectedGraph<String>({
39+
a: {b, h, c, e},
40+
d: {e, f},
41+
b: {h},
42+
c: {h, g},
43+
f: {i},
44+
i: {l},
45+
// h: {a},
46+
k: {g, f},
47+
}, comparator: comparator);
5748
for (var i = 1; i < 0; i++) {
5849
var nodes = graph.vertices.toList();
5950
for (var node in nodes) {

benchmark/graph_crawler_benchmark.dart

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
import 'package:benchmark_runner/benchmark_runner.dart';
22
import 'package:directed_graph/directed_graph.dart';
33

4-
int comparator(
5-
String s1,
6-
String s2,
7-
) {
4+
int comparator(String s1, String s2) {
85
return s1.compareTo(s2);
96
}
107

11-
int inverseComparator(
12-
String s1,
13-
String s2,
14-
) {
8+
int inverseComparator(String s1, String s2) {
159
return -s1.compareTo(s2);
1610
}
1711

@@ -27,18 +21,15 @@ var i = 'i';
2721
var k = 'k';
2822
var l = 'l';
2923

30-
var graph = DirectedGraph<String>(
31-
{
32-
a: {b, h, c, e},
33-
d: {e, f},
34-
b: {h},
35-
c: {h, g},
36-
f: {i},
37-
i: {l},
38-
k: {g, f}
39-
},
40-
comparator: comparator,
41-
);
24+
var graph = DirectedGraph<String>({
25+
a: {b, h, c, e},
26+
d: {e, f},
27+
b: {h},
28+
c: {h, g},
29+
f: {i},
30+
i: {l},
31+
k: {g, f},
32+
}, comparator: comparator);
4233

4334
var gc = GraphCrawler<String>(graph.edges);
4435

benchmark/weighted_directed_graph_benchmark.dart

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
import 'package:benchmark_runner/benchmark_runner.dart';
22
import 'package:directed_graph/directed_graph.dart';
33

4-
int comparator(
5-
String s1,
6-
String s2,
7-
) {
4+
int comparator(String s1, String s2) {
85
return s1.compareTo(s2);
96
}
107

11-
int inverseComparator(
12-
String s1,
13-
String s2,
14-
) {
8+
int inverseComparator(String s1, String s2) {
159
return -s1.compareTo(s2);
1610
}
1711

@@ -27,11 +21,7 @@ var i = 'i';
2721
var k = 'k';
2822
var l = 'l';
2923

30-
var graph = WeightedDirectedGraph<String, int>(
31-
{},
32-
summation: sum,
33-
zero: 0,
34-
);
24+
var graph = WeightedDirectedGraph<String, int>({}, summation: sum, zero: 0);
3525

3626
int sum(int left, int right) => left + right;
3727

example/bin/directed_graph_example.dart

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,17 @@ void main() {
1313

1414
// Constructing a graph from vertices.
1515

16-
final graph = DirectedGraph<String>(
17-
{
18-
'a': {'b', 'h', 'c', 'e'},
19-
'b': {'h'},
20-
'c': {'h', 'g'},
21-
'd': {'e', 'f'},
22-
'e': {'g'},
23-
'f': {'i'},
24-
//'g': {'a'},
25-
'i': {'l'},
26-
'k': {'g', 'f'},
27-
},
28-
comparator: comparator,
29-
);
16+
final graph = DirectedGraph<String>({
17+
'a': {'b', 'h', 'c', 'e'},
18+
'b': {'h'},
19+
'c': {'h', 'g'},
20+
'd': {'e', 'f'},
21+
'e': {'g'},
22+
'f': {'i'},
23+
//'g': {'a'},
24+
'i': {'l'},
25+
'k': {'g', 'f'},
26+
}, comparator: comparator);
3027

3128
print('Example Directed Graph...');
3229
print('graph.toString():');

example/bin/graph_crawler_example.dart

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import 'package:directed_graph/directed_graph.dart';
22

33
void main(List<String> args) {
4-
int comparator(
5-
String s1,
6-
String s2,
7-
) {
4+
int comparator(String s1, String s2) {
85
return s1.compareTo(s2);
96
}
107

@@ -33,7 +30,7 @@ void main(List<String> args) {
3330
h: {a: 7},
3431
i: {l: 3, k: 2},
3532
k: {g: 4, f: 5},
36-
l: {l: 0}
33+
l: {l: 0},
3734
},
3835
summation: sum,
3936
zero: 0,
@@ -51,8 +48,5 @@ void main(List<String> args) {
5148
print(crawler.mappedTree(a, h));
5249

5350
print('\nTruncated tree with root vertex a and target h:');
54-
print(graph.crawler.paths(
55-
a,
56-
h,
57-
));
51+
print(graph.crawler.paths(a, h));
5852
}

example/bin/weighted_graph_example.dart

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import 'package:directed_graph/directed_graph.dart';
22

33
void main(List<String> args) {
4-
int comparator(
5-
String s1,
6-
String s2,
7-
) {
4+
int comparator(String s1, String s2) {
85
return s1.compareTo(s2);
96
}
107

@@ -32,7 +29,7 @@ void main(List<String> args) {
3229
f: {i: 3},
3330
i: {l: 3, k: 2},
3431
k: {g: 4, f: 5},
35-
l: {l: 0}
32+
l: {l: 0},
3633
},
3734
summation: sum,
3835
zero: 0,

lib/src/extensions/sort.dart

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ extension SortSet<T extends Object> on Set<T> {
1818
tmp.sort(); // Sort using default comparator.
1919
} else {
2020
throw ErrorOfType<SortingNotSupported<T>>(
21-
message: 'Error trying to sort the set: $this.',
22-
invalidState: 'Type \'$T\' is not comparable.',
23-
expectedState: 'Try specifying a valid comparator for type \'$T\'.');
21+
message: 'Error trying to sort the set: $this.',
22+
invalidState: 'Type \'$T\' is not comparable.',
23+
expectedState: 'Try specifying a valid comparator for type \'$T\'.',
24+
);
2425
}
2526
clear();
2627
addAll(tmp);
@@ -44,10 +45,12 @@ extension SortMap<K extends Object, V extends Object> on Map<K, V> {
4445
tmp.sort((left, right) => (left.key as Comparable).compareTo(right.key));
4546
} else {
4647
throw ErrorOfType<SortingNotSupported<K>>(
47-
message: 'Error trying to sort $this using the keys $keys.',
48-
invalidState: 'Type \'$K\' is not comparable.',
49-
expectedState: 'Try calling sortByKey() '
50-
'specifying a valid comparator for type \'$K\'.');
48+
message: 'Error trying to sort $this using the keys $keys.',
49+
invalidState: 'Type \'$K\' is not comparable.',
50+
expectedState:
51+
'Try calling sortByKey() '
52+
'specifying a valid comparator for type \'$K\'.',
53+
);
5154
}
5255
clear();
5356
addEntries(tmp);
@@ -68,10 +71,12 @@ extension SortMap<K extends Object, V extends Object> on Map<K, V> {
6871
);
6972
} else {
7073
throw ErrorOfType<SortingNotSupported<V>>(
71-
message: 'Error trying to sort a map of type Map<$K, $V>.',
72-
invalidState: 'Type \'$V\' is not comparable.',
73-
expectedState: 'Try calling sortByValue() specifying '
74-
'a valid comparator for type \'$V\'.');
74+
message: 'Error trying to sort a map of type Map<$K, $V>.',
75+
invalidState: 'Type \'$V\' is not comparable.',
76+
expectedState:
77+
'Try calling sortByValue() specifying '
78+
'a valid comparator for type \'$V\'.',
79+
);
7580
}
7681
clear();
7782
addEntries(tmp);

lib/src/graphs/bidirected_graph.dart

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,14 @@ import 'directed_graph.dart';
33
/// Graph with bidirected edges represented by a directed graph
44
/// with symmetric edges.
55
class BidirectedGraph<T extends Object> extends DirectedGraph<T> {
6-
BidirectedGraph(
7-
super.edges, {
8-
super.comparator,
9-
}) {
6+
BidirectedGraph(super.edges, {super.comparator}) {
107
// Render graph symmetric:
118
_symmetrize();
129
}
1310

1411
/// Constructs a bidirected graph from a directed graph.
1512
BidirectedGraph.from(DirectedGraph<T> graph)
16-
: super(
17-
graph.data,
18-
comparator: graph.comparator,
19-
) {
13+
: super(graph.data, comparator: graph.comparator) {
2014
_symmetrize();
2115
}
2216

lib/src/graphs/directed_graph.dart

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ class DirectedGraph<T extends Object> extends DirectedGraphBase<T> {
99
/// * `edges`: a map of type `Map<T, Set<T>>`,
1010
/// * `comparator`: a function with typedef `Comparator<T>` used to sort
1111
/// the graph vertices.
12-
DirectedGraph(
13-
Map<T, Set<T>> edges, {
14-
Comparator<T>? comparator,
15-
}) : super(comparator) {
12+
DirectedGraph(Map<T, Set<T>> edges, {Comparator<T>? comparator})
13+
: super(comparator) {
1614
edges.forEach((vertex, connectedVertices) {
1715
_edges[vertex] = Set<T>.of(connectedVertices);
1816
for (final connectedVertex in connectedVertices) {
@@ -23,15 +21,13 @@ class DirectedGraph<T extends Object> extends DirectedGraphBase<T> {
2321

2422
/// Constructs a shallow copy of `graph`.
2523
DirectedGraph.of(DirectedGraph<T> graph)
26-
: this(
27-
graph.data,
28-
comparator: graph.comparator,
29-
);
24+
: this(graph.data, comparator: graph.comparator);
3025

3126
/// Constructs a directed graph from a map of weighted edges.
32-
DirectedGraph.fromWeightedEdges(Map<T, Map<T, dynamic>> weightedEdges,
33-
{Comparator<T>? comparator})
34-
: super(comparator) {
27+
DirectedGraph.fromWeightedEdges(
28+
Map<T, Map<T, dynamic>> weightedEdges, {
29+
Comparator<T>? comparator,
30+
}) : super(comparator) {
3531
weightedEdges.forEach((vertex, connectedVerticeWeights) {
3632
_edges[vertex] = Set<T>.of(connectedVerticeWeights.keys);
3733
for (final connectedVertex in connectedVerticeWeights.keys) {

lib/src/graphs/directed_graph_base.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ abstract class DirectedGraphBase<T extends Object> extends Iterable<T> {
1515
/// Super constructor of objects extending `DirectedGraphBase`.
1616
/// * `comparator`: A function with signature `int Function(T a, T b)`
1717
/// used to sort vertices.
18-
DirectedGraphBase(
19-
Comparator<T>? comparator,
20-
) : _comparator = comparator {
18+
DirectedGraphBase(Comparator<T>? comparator) : _comparator = comparator {
2119
if (_comparator == null && T is Comparable) {
2220
_comparator = (T left, T right) {
2321
return (left as Comparable).compareTo(right);
@@ -62,8 +60,9 @@ abstract class DirectedGraphBase<T extends Object> extends Iterable<T> {
6260
}
6361

6462
/// Caches the sorted vertices.
65-
late final LazySet<T> _sortedVertices =
66-
LazySet<T>(() => vertices.toSet()..sort(comparator));
63+
late final LazySet<T> _sortedVertices = LazySet<T>(
64+
() => vertices.toSet()..sort(comparator),
65+
);
6766

6867
/// Returns an `Iterable<T>` of all vertices.
6968
Iterable<T> get vertices;

0 commit comments

Comments
 (0)