@@ -15,12 +15,14 @@ class Vertex<T> {
15
15
final LinkedHashSet <Vertex > _incomingVertices;
16
16
17
17
/// Incoming connections from this [Vertex]
18
- LinkedHashSet <Vertex > get incomingVertices => _incomingVertices;
18
+ List <Vertex > get incomingVertices =>
19
+ List <Vertex >.unmodifiable (_incomingVertices);
19
20
20
21
final LinkedHashMap <Vertex , num > _outgoingConnections;
21
22
22
23
/// Outgoing connections from this [Vertex]
23
- LinkedHashMap <Vertex , num > get outgoingConnections => _outgoingConnections;
24
+ UnmodifiableMapView <Vertex , num > get outgoingConnections =>
25
+ Map <Vertex , num >.unmodifiable (_outgoingConnections);
24
26
25
27
/// Constructor
26
28
Vertex (this ._key, [T value])
@@ -31,7 +33,7 @@ class Vertex<T> {
31
33
32
34
/// Adds a connection with [Vertex] `dst` and with `weight`
33
35
bool addConnection (Vertex dst, [num weight = 1 ]) {
34
- if (outgoingConnections .containsKey (dst)) {
36
+ if (_outgoingConnections .containsKey (dst)) {
35
37
return false ;
36
38
}
37
39
_outgoingConnections[dst] = weight;
@@ -50,23 +52,24 @@ class Vertex<T> {
50
52
51
53
/// Checks if [Vertex] `other` is connected to this vertex
52
54
bool containsConnectionTo (Vertex other) =>
53
- outgoingConnections .containsKey (other);
55
+ _outgoingConnections .containsKey (other);
54
56
55
57
/// Checks if [Vertex] `other` is connected to this vertex
56
- bool containsConnectionFrom (Vertex other) => incomingVertices.contains (other);
58
+ bool containsConnectionFrom (Vertex other) =>
59
+ _incomingVertices.contains (other);
57
60
58
61
/// Get a list of adjacent outgoing vertices
59
62
Set <Vertex > get outgoingVertices =>
60
- outgoingConnections .keys.map ((connection) => connection).toSet ();
63
+ _outgoingConnections .keys.map ((connection) => connection).toSet ();
61
64
62
65
/// Is this vertex isolated?
63
- bool get isIsolated => outgoingConnections .isEmpty;
66
+ bool get isIsolated => _outgoingConnections .isEmpty;
64
67
65
68
/// Calculate the inDegree of the vertex
66
- int get inDegree => incomingVertices .length;
69
+ int get inDegree => _incomingVertices .length;
67
70
68
71
/// Calculate the outDegree of the vertex
69
- int get outDegree => outgoingConnections .length;
72
+ int get outDegree => _outgoingConnections .length;
70
73
71
74
@override
72
75
String toString () => key;
0 commit comments