Changeset 10884 for branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/DirectedGraph.cs
- Timestamp:
- 05/21/14 23:39:19 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/DirectedGraph.cs
r10833 r10884 33 33 public class DirectedGraph : Item, IDirectedGraph { 34 34 [Storable] 35 pr otectedreadonly List<IVertex> nodes; // for performance reasons, maybe this should be a linked list (fast remove)36 public List<IVertex> Nodes {35 private readonly List<IVertex> nodes; // for performance reasons, maybe this should be a linked list (fast remove) 36 public IEnumerable<IVertex> Nodes { 37 37 get { return nodes; } 38 38 } 39 40 [Storable] 41 private readonly Dictionary<string, IVertex> idMap; 42 39 43 [Storable] 40 44 private readonly Dictionary<object, IVertex> contentMap; … … 42 46 nodes = new List<IVertex>(); 43 47 contentMap = new Dictionary<object, IVertex>(); 48 idMap = new Dictionary<string, IVertex>(); 44 49 } 45 50 [StorableConstructor] … … 51 56 nodes = new List<IVertex>(original.Nodes); 52 57 contentMap = new Dictionary<object, IVertex>(original.contentMap); 58 idMap = new Dictionary<string, IVertex>(original.idMap); 53 59 } 54 60 public override IDeepCloneable Clone(Cloner cloner) { … … 62 68 return contentMap.ContainsKey(content); 63 69 } 70 71 public IVertex GetVertex(string id) { 72 IVertex result; 73 idMap.TryGetValue(id, out result); 74 return result; 75 } 76 64 77 public IVertex this[object key] { 65 78 get { … … 69 82 } 70 83 set { 84 if (contentMap.ContainsKey(key)) { 85 idMap.Remove(contentMap[key].Id); 86 } 71 87 contentMap[key] = value; 88 idMap[value.Id] = value; 72 89 } 73 90 } … … 81 98 nodes.Clear(); 82 99 contentMap.Clear(); 100 idMap.Clear(); 83 101 } 84 102 public virtual void AddVertex(IVertex vertex) { … … 87 105 } 88 106 contentMap[vertex.Content] = vertex; 89 Nodes.Add(vertex); 107 idMap[vertex.Id] = vertex; 108 nodes.Add(vertex); 90 109 } 91 110
Note: See TracChangeset
for help on using the changeset viewer.