Skip to content

Commit 15ac76a

Browse files
committed
Added comments related to quasi-topological ordering.
1 parent 4e476ad commit 15ac76a

3 files changed

Lines changed: 13 additions & 13 deletions

File tree

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ Hereby, dashed edges were disregarded since a cyclic graph does not have a topol
5959
- *Quasi-Topological ordering*: An ordered *sub-set* of graph vertices
6060
such that v<sub>i</sub>
6161
occurs before v<sub>j</sub> if there is a directed edge (v<sub>i</sub>, v<sub>j</sub>).
62-
For a quasi-topological ordering to exist, any two vertices belonging to the *sub-set* must not have mutually connecting edges.
62+
For a quasi-topological ordering to exist, any two vertices belonging to the *sub-set*
63+
must not be mutually connected. That is, if there is a path \[v<sub>i</sub>, ..., v<sub>j</sub>\]
64+
then there must not be a path \[v<sub>j</sub>, ..., v<sub>i</sub>\] and vice versa.
6365

64-
65-
*Note*: In the context of this package the definition of *edge* might be more lax compared to a
66+
*Note*: In the context of this package, the definition of *edge* might be more lax compared to a
6667
rigorous mathematical definition.
6768
For example, self-loops, that is edges connecting a vertex to itself are explicitly allowed.
6869

lib/src/graphs/directed_graph_base.dart

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,18 +164,14 @@ abstract class DirectedGraphBase<T extends Object> extends Iterable<T> {
164164
/// including cycles.
165165
/// * Returns an empty list if no path was found.
166166
/// * To exclude cycles use the method `shortestPath(start, target)`.
167-
List<T> path(T start, T target) {
168-
return crawler.path(start, target);
169-
}
167+
List<T> path(T start, T target) => crawler.path(start, target);
170168

171169
/// Returns all paths from [start] to [target]
172170
/// including cycles.
173171
/// * Returns an empty list if no path was found.
174172
/// * To exclude cycles and list only the shortest paths
175173
/// use the method `shortestPaths(start, target)`.
176-
List<List<T>> paths(T start, T target) {
177-
return crawler.paths(start, target);
178-
}
174+
List<List<T>> paths(T start, T target) => crawler.paths(start, target);
179175

180176
/// Returns the first cycle detected or an empty list
181177
/// if the graph is acyclic.
@@ -574,11 +570,12 @@ abstract class DirectedGraphBase<T extends Object> extends Iterable<T> {
574570
}
575571

576572
/// Returns a set containing the elements of [vertices]
577-
/// in quasi topological insertion order if there is not mutual connection
578-
/// between any two elements of [vertices].
579-
///
573+
/// in quasi-topological insertion order.
580574
/// * [vertices] must be a subset of the graph vertices. If any vertex in
581575
/// [vertices] does not belong to the graph, `null` is returned.
576+
/// * Note: If A and B are any two elements of [vertices],
577+
/// and there is a path [A, ..., B], then there be no path [B, ..., A]
578+
/// for a quasi-topological ordering to exists.
582579
/// * If sorted is set to
583580
/// `true` the vertices will be ordered using the graph [comparator] on top
584581
/// of the topological sort.

lib/src/graphs/graph_crawler.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ class GraphCrawler<T extends Object> {
2929
final Edges<T> edges;
3030

3131
/// Returns the shortest path from [start] to [target].
32+
///
3233
/// * Returns an empty list if [target] is not reachable from [start].
34+
///
3335
List<T> path(T start, T target) {
3436
final tree = <Set<T>>[];
3537
for (final connected in edges(start)) {
@@ -51,7 +53,7 @@ class GraphCrawler<T extends Object> {
5153
var startIndex = 0;
5254
var endIndex = 0;
5355
var length = tree.length;
54-
final visited = HashSet<T>()..add(start);
56+
final visited = HashSet<T>();
5557
do {
5658
endIndex = tree.length;
5759
for (var i = startIndex; i < endIndex; ++i) {

0 commit comments

Comments
 (0)