Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/StatefullExpression.cs @ 14730

Last change on this file since 14730 was 14730, checked in by mkommend, 7 years ago

#2665: Removed memory pressure from expressions.

File size: 955 bytes
RevLine 
[14727]1namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
2
3  public abstract class StatefullExpression<T> : Expression {
4
5    public readonly T State;
6
[14730]7    private int hashCode;
8    private int HashCode {
9      get {
10        if (hashCode == default(int)) hashCode = CalcHashCode();
11        return hashCode;
12      }
13    }
14
[14727]15    protected StatefullExpression(T state) {
16      this.State = state;
17    }
18
19    protected virtual int CalcHashCode() {
20      return this.State.GetHashCode();
21    }
22
23    public override bool Equals(object obj) {
24      if (ReferenceEquals(this, obj))
25        return true;
26
27      if (this.GetType() != obj.GetType())
28        return false;
29
30      var other = (StatefullExpression<T>)obj;
31
32      return ReferenceEquals(this.State, other.State) ||
33             this.GetHashCode() == other.GetHashCode();
34    }
35
36    public override int GetHashCode() {
[14730]37      return HashCode;
[14727]38    }
39  }
40}
Note: See TracBrowser for help on using the repository browser.