Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/15/18 14:53:46 (6 years ago)
Author:
bburlacu
Message:

#2886: Fix serialization and cloning and plugin properties.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/Hashing/Hasher.cs

    r15851 r15960  
    33using System.Diagnostics;
    44using System.Linq;
     5using HeuristicLab.Common;
     6using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    57
    68namespace HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration.GrammarEnumeration {
    7   public abstract class Hasher<THashType> {
     9  [StorableClass]
     10  public abstract class Hasher<THashType> : DeepCloneable {
    811    protected Hasher(Grammar grammar) {
    912      Grammar = grammar;
     13    }
     14
     15    protected Hasher(Hasher<THashType> original, Cloner cloner) : base(original, cloner) {
     16      Grammar = cloner.Clone(original.Grammar);
    1017    }
    1118
     
    2229      return AggregateHashes(peek, GetSubtreeHashes(parseStack)).GetHashCode();
    2330    }
     31
     32    [StorableConstructor]
     33    protected Hasher(bool deserializing) { }
    2434
    2535    private THashType[] GetSubtreeHashes(Stack<Symbol> parseStack) {
     
    109119        .ToArray();
    110120    }
    111 
    112 
    113121  }
    114122
     123  [StorableClass]
    115124  public class IntHasher : Hasher<int> {
    116125    public IntHasher(Grammar grammar) : base(grammar) { }
     126
     127    public IntHasher(IntHasher original, Cloner cloner) : base(original, cloner) { }
     128
     129    public override IDeepCloneable Clone(Cloner cloner) {
     130      return new IntHasher(this, cloner);
     131    }
     132
     133    [StorableConstructor]
     134    protected IntHasher(bool deserializing) : base(deserializing) { }
    117135
    118136    protected override int AggregateHashes(Symbol operatorSym, int[] hashes) {
     
    135153  }
    136154
     155  [StorableClass]
    137156  public class StringHasher : Hasher<string> {
    138157    public StringHasher(Grammar grammar) : base(grammar) { }
     158
     159    public StringHasher(StringHasher original, Cloner cloner) : base(original, cloner) { }
     160
     161    public override IDeepCloneable Clone(Cloner cloner) {
     162      return new StringHasher(this, cloner);
     163    }
     164
     165    [StorableConstructor]
     166    protected StringHasher(bool deserializing) : base(deserializing) { }
    139167
    140168    protected override string AggregateHashes(Symbol operatorSym, string[] hashes) {
Note: See TracChangeset for help on using the changeset viewer.