source: branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/ReadonlySequence.cs @ 11742

Last change on this file since 11742 was 11742, checked in by gkronber, 6 years ago

#2283 refactoring

File size: 1008 bytes
Line 
1using System;
2
3namespace HeuristicLab.Problems.GrammaticalOptimization {
4  public class ReadonlySequence : Sequence {
5    public ReadonlySequence(string s)
6      : base(s, s.Length) {
7    }
8
9    public ReadonlySequence(char ch)
10      : base(ch, 1) {
11    }
12
13    public ReadonlySequence(Sequence s)
14      : base(s, s.Length) {
15    }
16
17    public override void ReplaceAt(int position, int len, Sequence replacement) {
18      throw new NotSupportedException();
19    }
20
21    public override bool Equals(object obj) {
22      var other = obj as Sequence;
23      if (other == null) return false;
24      if (other.Length != this.Length) return false;
25      for (int i = 0; i < Length; i++)
26        if (other[i] != this[i]) return false;
27
28      // length and all symbols are the same
29      return true;
30    }
31
32    public override int GetHashCode() {
33      int h = 31 * Length;
34      for (int i = 0; i < Length; i++) {
35        h += 31 * (byte)this[i];
36      }
37      return h;
38    }
39  }
40}
Note: See TracBrowser for help on using the repository browser.