Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/10/17 21:42:09 (7 years ago)
Author:
pkimmesw
Message:

#2665 Renamings due to typos, ManagedPool tests, Skip Noops in Debugger

File:
1 edited

Legend:

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

    r14730 r14744  
    22
    33namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
    4   using System;
    54  using System.Diagnostics;
    65  using System.Linq;
     
    1413    private const string Delimiter = " ";
    1514
     15    public static readonly PushProgram Empty = new PushProgram(new Expression[0]);
     16
    1617    public readonly IReadOnlyList<Expression> Expressions;
    17     public readonly bool IsEmpty;
    18 
     18    public bool IsEmpty { get; private set; }
     19
     20    public PushProgram(Expression[] expressions) {
     21      this.Expressions = expressions;
     22      this.IsEmpty = expressions.Length == 0;
     23    }
    1924
    2025    private string stringRepresentation;
    21     private string StringRepresentation {
    22       get {
     26    private string StringRepresentation
     27    {
     28      get
     29      {
    2330        if (string.IsNullOrEmpty(stringRepresentation))
    2431          stringRepresentation = BuildString();
     
    2835
    2936    private int depth = -1;
    30     private int Depth {
    31       get {
     37    private int Depth
     38    {
     39      get
     40      {
    3241        if (depth == -1) depth = CalcDepth();
    3342        return depth;
     
    3645
    3746    private int[] treeIndex = null;
    38     public int[] TreeIndex {
    39       get {
    40         if (treeIndex == null) treeIndex = BuildTreeIndex();
    41         return treeIndex;
     47    public int[] TreeIndex
     48    {
     49      get
     50      {
     51        return this.treeIndex ?? (this.treeIndex = this.BuildTreeIndex());
    4252      }
    4353    }
    4454
    4555    private int hashCode;
    46     private int HashCode {
    47       get {
     56    private int HashCode
     57    {
     58      get
     59      {
    4860        if (hashCode == default(int)) hashCode = HashExpressions();
    4961        return hashCode;
    5062      }
    5163    }
    52 
    53     public PushProgram(Expression[] expressions) {
    54       this.Expressions = expressions;
    55       this.IsEmpty = expressions.Length == 0;
    56     }
    57 
    5864
    5965    public override int GetHashCode() {
     
    6975    /// </summary>
    7076    /// <returns></returns>
    71     public int TotalCount {
    72       get {
     77    public int TotalCount
     78    {
     79      get
     80      {
    7381        return this.IsEmpty
    7482            ? 1
    75           // + 1 because "this" is also counted
     83            // + 1 because "this" is also counted
    7684            : TreeIndex[0] + 1;
    7785      }
     
    9098
    9199    public PushProgram Copy() {
    92       var copy = this.CopyExpressions();
    93 
    94       return new PushProgram(copy);
     100      return IsEmpty ? this : new PushProgram((Expression[])Expressions) {
     101        stringRepresentation = this.stringRepresentation,
     102        hashCode = this.hashCode,
     103        depth = this.depth,
     104        treeIndex = this.treeIndex
     105      };
    95106    }
    96107
    97108    public Expression[] CopyExpressions() {
    98109      var copy = new Expression[this.Expressions.Count];
    99       Array.Copy((Expression[])this.Expressions, copy, this.Expressions.Count);
     110      ((Expression[])this.Expressions).CopyTo(copy, Expressions.Count);
    100111
    101112      return copy;
Note: See TracChangeset for help on using the changeset viewer.