OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library dependency_graph; | 5 library dependency_graph; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'utils.dart'; | 8 import 'utils.dart'; |
9 | 9 |
10 | |
11 /* | 10 /* |
12 * [Graph] represents a datastructure for representing an DAG (directed acyclic | 11 * [Graph] represents a datastructure for representing an DAG (directed acyclic |
13 * graph). Each node in the graph is in a given [NodeState] and can have data | 12 * graph). Each node in the graph is in a given [NodeState] and can have data |
14 * attachted to it with [Node.userData]. | 13 * attachted to it with [Node.userData]. |
15 * | 14 * |
16 * It's interface consists basically of these methods: | 15 * It's interface consists basically of these methods: |
17 * - newNode: Adds a new node to the graph with the given dependencies and | 16 * - newNode: Adds a new node to the graph with the given dependencies and |
18 * the given user data. The node is in the [NodeState.Initialized] | 17 * the given user data. The node is in the [NodeState.Initialized] |
19 * state. | 18 * state. |
20 * - changeState: Changes the state of a node. | 19 * - changeState: Changes the state of a node. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 Node._(this._userData); | 106 Node._(this._userData); |
108 | 107 |
109 Object get userData => _userData; | 108 Object get userData => _userData; |
110 NodeState get state => _state; | 109 NodeState get state => _state; |
111 Iterable<Node> get dependencies => _dependencies; | 110 Iterable<Node> get dependencies => _dependencies; |
112 Iterable<Node> get neededFor => _neededFor; | 111 Iterable<Node> get neededFor => _neededFor; |
113 } | 112 } |
114 | 113 |
115 class NodeState extends UniqueObject { | 114 class NodeState extends UniqueObject { |
116 static NodeState Initialized = new NodeState._("Initialized"); | 115 static NodeState Initialized = new NodeState._("Initialized"); |
117 static NodeState Waiting = new NodeState._("Waiting"); | 116 static NodeState Waiting = new NodeState._("Waiting"); |
118 static NodeState Enqueuing = new NodeState._("Enqueuing"); | 117 static NodeState Enqueuing = new NodeState._("Enqueuing"); |
119 static NodeState Processing = new NodeState._("Running"); | 118 static NodeState Processing = new NodeState._("Running"); |
120 static NodeState Successful = new NodeState._("Successful"); | 119 static NodeState Successful = new NodeState._("Successful"); |
121 static NodeState Failed = new NodeState._("Failed"); | 120 static NodeState Failed = new NodeState._("Failed"); |
122 static NodeState UnableToRun = new NodeState._("UnableToRun"); | 121 static NodeState UnableToRun = new NodeState._("UnableToRun"); |
123 | 122 |
124 final String name; | 123 final String name; |
125 | 124 |
126 NodeState._(this.name); | 125 NodeState._(this.name); |
127 | 126 |
128 String toString() => name; | 127 String toString() => name; |
129 } | 128 } |
130 | 129 |
131 abstract class GraphEvent {} | 130 abstract class GraphEvent {} |
132 | 131 |
133 class GraphSealedEvent extends GraphEvent {} | 132 class GraphSealedEvent extends GraphEvent {} |
134 | 133 |
135 class NodeAddedEvent extends GraphEvent { | 134 class NodeAddedEvent extends GraphEvent { |
136 final Node node; | 135 final Node node; |
137 | 136 |
138 NodeAddedEvent(this.node); | 137 NodeAddedEvent(this.node); |
139 } | 138 } |
140 | 139 |
141 class StateChangedEvent extends GraphEvent { | 140 class StateChangedEvent extends GraphEvent { |
142 final Node node; | 141 final Node node; |
143 final NodeState from; | 142 final NodeState from; |
144 final NodeState to; | 143 final NodeState to; |
145 | 144 |
146 StateChangedEvent(this.node, this.from, this.to); | 145 StateChangedEvent(this.node, this.from, this.to); |
147 } | 146 } |
OLD | NEW |