Last change
on this file since 14745 was
14745,
checked in by pkimmesw, 7 years ago
|
#2665 Merged ExecExpandExpression and PushProgram due to performance reasons, Tested managed object pooling
|
File size:
960 bytes
|
Line | |
---|
1 | namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
|
---|
2 | public abstract class StatefulExpression<T> : Expression {
|
---|
3 | 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 | }
|
---|
14 |
|
---|
15 | protected StatefulExpression(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 = (StatefulExpression<T>)obj;
|
---|
31 |
|
---|
32 | return ReferenceEquals(this.State, other.State) ||
|
---|
33 | this.GetHashCode() == other.GetHashCode();
|
---|
34 | }
|
---|
35 |
|
---|
36 | public override int GetHashCode() {
|
---|
37 | return HashCode;
|
---|
38 | }
|
---|
39 | }
|
---|
40 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.