Last change
on this file since 14744 was
14744,
checked in by pkimmesw, 7 years ago
|
#2665 Renamings due to typos, ManagedPool tests, Skip Noops in Debugger
|
File size:
1.0 KB
|
Line | |
---|
1 | namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
|
---|
2 | using HeuristicLab.Problems.ProgramSynthesis.Push.Data.Pool;
|
---|
3 |
|
---|
4 | public abstract class StatefulExpression<T> : Expression
|
---|
5 | {
|
---|
6 | public readonly T State;
|
---|
7 |
|
---|
8 | private int hashCode;
|
---|
9 | private int HashCode
|
---|
10 | {
|
---|
11 | get
|
---|
12 | {
|
---|
13 | if (hashCode == default(int)) hashCode = CalcHashCode();
|
---|
14 | return hashCode;
|
---|
15 | }
|
---|
16 | }
|
---|
17 |
|
---|
18 | protected StatefulExpression(T state) {
|
---|
19 | this.State = state;
|
---|
20 | }
|
---|
21 |
|
---|
22 | protected virtual int CalcHashCode() {
|
---|
23 | return this.State.GetHashCode();
|
---|
24 | }
|
---|
25 |
|
---|
26 | public override bool Equals(object obj) {
|
---|
27 | if (ReferenceEquals(this, obj))
|
---|
28 | return true;
|
---|
29 |
|
---|
30 | if (this.GetType() != obj.GetType())
|
---|
31 | return false;
|
---|
32 |
|
---|
33 | var other = (StatefulExpression<T>)obj;
|
---|
34 |
|
---|
35 | return ReferenceEquals(this.State, other.State) ||
|
---|
36 | this.GetHashCode() == other.GetHashCode();
|
---|
37 | }
|
---|
38 |
|
---|
39 | public override int GetHashCode() {
|
---|
40 | return HashCode;
|
---|
41 | }
|
---|
42 | }
|
---|
43 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.