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