File tree Expand file tree Collapse file tree 3 files changed +10
-4
lines changed Expand file tree Collapse file tree 3 files changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -2,8 +2,9 @@ import 'vertex.dart';
2
2
3
3
/// A Graph Type
4
4
class Graph <T > {
5
- /// Vertices of this graph
6
5
Set <Vertex <T >> _vertices;
6
+
7
+ /// Vertices of this graph
7
8
List <Vertex <T >> get vertices => List <Vertex <T >>.unmodifiable (_vertices);
8
9
9
10
/// Settings for this graph
Original file line number Diff line number Diff line change @@ -33,13 +33,17 @@ class Vertex<T> {
33
33
this .value = value ?? key;
34
34
}
35
35
36
+ /// Lock [this] vertex, cannot modify after it is locked
36
37
void lock () => _isLocked = true ;
38
+
39
+ /// Unlock [this] vertex, can modify after it is unlock
37
40
void unlock () => _isLocked = false ;
38
41
39
42
/// Adds a connection with [Vertex] `dst` and with `weight`
40
43
bool addConnection (Vertex dst, [num weight = 1 ]) {
41
- if (_isLocked || dst._isLocked)
44
+ if (_isLocked || dst._isLocked) {
42
45
throw UnsupportedError ('Cannot add to a locked vertex' );
46
+ }
43
47
if (_outgoingConnections.containsKey (dst)) {
44
48
return false ;
45
49
}
@@ -51,8 +55,9 @@ class Vertex<T> {
51
55
/// Removes a connection with `other` with `weight` . `false` for non-existent
52
56
/// connection.
53
57
bool removeConnection (Vertex other, [num weight = 1 ]) {
54
- if (_isLocked || other._isLocked)
58
+ if (_isLocked || other._isLocked) {
55
59
throw UnsupportedError ('Cannot remove from a locked vertex' );
60
+ }
56
61
var outgoingRemoved = _outgoingConnections.remove (other) != null ;
57
62
var incomingRemoved = other._incomingVertices.remove (this );
58
63
Original file line number Diff line number Diff line change @@ -131,7 +131,7 @@ void main() {
131
131
});
132
132
133
133
test ('Get out degree for vertex' , () {
134
- Vertex c = Vertex ('c' );
134
+ var c = Vertex ('c' );
135
135
c.unlock ();
136
136
expect (root.outDegree, equals (0 ));
137
137
connectedVertex.addConnection (c);
You can’t perform that action at this time.
0 commit comments