Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/21/14 23:39:19 (10 years ago)
Author:
bburlacu
Message:

#1772: Added license headers where they were missing. Introduced an id map to the DirectedGraph to get graph vertices based on the id injected in the scopes by the genealogy analyzer.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/DirectedGraph.cs

    r10833 r10884  
    3333  public class DirectedGraph : Item, IDirectedGraph {
    3434    [Storable]
    35     protected readonly 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 {
    3737      get { return nodes; }
    3838    }
     39
     40    [Storable]
     41    private readonly Dictionary<string, IVertex> idMap;
     42
    3943    [Storable]
    4044    private readonly Dictionary<object, IVertex> contentMap;
     
    4246      nodes = new List<IVertex>();
    4347      contentMap = new Dictionary<object, IVertex>();
     48      idMap = new Dictionary<string, IVertex>();
    4449    }
    4550    [StorableConstructor]
     
    5156      nodes = new List<IVertex>(original.Nodes);
    5257      contentMap = new Dictionary<object, IVertex>(original.contentMap);
     58      idMap = new Dictionary<string, IVertex>(original.idMap);
    5359    }
    5460    public override IDeepCloneable Clone(Cloner cloner) {
     
    6268      return contentMap.ContainsKey(content);
    6369    }
     70
     71    public IVertex GetVertex(string id) {
     72      IVertex result;
     73      idMap.TryGetValue(id, out result);
     74      return result;
     75    }
     76
    6477    public IVertex this[object key] {
    6578      get {
     
    6982      }
    7083      set {
     84        if (contentMap.ContainsKey(key)) {
     85          idMap.Remove(contentMap[key].Id);
     86        }
    7187        contentMap[key] = value;
     88        idMap[value.Id] = value;
    7289      }
    7390    }
     
    8198      nodes.Clear();
    8299      contentMap.Clear();
     100      idMap.Clear();
    83101    }
    84102    public virtual void AddVertex(IVertex vertex) {
     
    87105      }
    88106      contentMap[vertex.Content] = vertex;
    89       Nodes.Add(vertex);
     107      idMap[vertex.Id] = vertex;
     108      nodes.Add(vertex);
    90109    }
    91110
Note: See TracChangeset for help on using the changeset viewer.