Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/11/17 20:07:13 (8 years ago)
Author:
pkimmesw
Message:

#2665 PooledPushProgram reduces memory usage and increases performance

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/StatefulExpression.cs

    r14745 r14746  
    22  public abstract class StatefulExpression<T> : Expression {
    33    public readonly T State;
    4 
    5     private int hashCode;
    6     private int HashCode
    7     {
    8       get
    9       {
    10         if (hashCode == default(int)) hashCode = CalcHashCode();
    11         return hashCode;
    12       }
    13     }
     4    private int? hashCode;
    145
    156    protected StatefulExpression(T state) {
     
    3425    }
    3526
     27    public bool Equals(StatefulExpression<T> obj) {
     28      if (ReferenceEquals(this, obj))
     29        return true;
     30
     31      if (GetType() != obj.GetType())
     32        return false;
     33
     34      return ReferenceEquals(State, obj.State) ||
     35             GetHashCode() == obj.GetHashCode();
     36    }
     37
    3638    public override int GetHashCode() {
    37       return HashCode;
     39      if (hashCode == null) hashCode = CalcHashCode();
     40      return hashCode.Value;
    3841    }
    3942  }
Note: See TracChangeset for help on using the changeset viewer.