Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/01/17 16:43:54 (8 years ago)
Author:
bburlacu
Message:

#1772: QueryMatch.cs: implement caching of NodeInfo lists to improve performance when repeatedly matching trees against schemas.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/QueryMatch.cs

    r14426 r14634  
    3535    private readonly ISymbolicExpressionTreeNodeComparer nodeComparer = new SymbolicExpressionTreeNodeComparer();
    3636
     37    private readonly Dictionary<ISymbolicExpressionTreeNode, List<NodeInfo>> cache = new Dictionary<ISymbolicExpressionTreeNode, List<NodeInfo>>();
     38
     39    public void ClearCache() {
     40      cache.Clear();
     41    }
     42
    3743    private QueryMatch() { }
    3844
     
    6369        return false;
    6470
    65       var dNodes = InitializePostOrder(data);
    66       var qNodes = InitializePostOrder(query);
     71      List<NodeInfo> dNodes, qNodes;
     72
     73      if (!cache.TryGetValue(data, out dNodes)) {
     74        dNodes = InitializePostOrder(data);
     75        cache[data] = dNodes;
     76      }
     77
     78      if (!cache.TryGetValue(query, out qNodes)) {
     79        qNodes = InitializePostOrder(query);
     80        cache[query] = qNodes;
     81      }
    6782
    6883      var dRoot = dNodes.Last();
Note: See TracChangeset for help on using the changeset viewer.