Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 11732 was 11732, checked in by gkronber, 9 years ago

#2283: refactoring and bug fixes

File size: 955 bytes
Line 
1using System;
2
3namespace HeuristicLab.Problems.GrammaticalOptimization {
4  public class ReadonlySequence : Sequence {
5    public ReadonlySequence(string s)
6      : base(s) {
7    }
8
9    public ReadonlySequence(char ch)
10      : base(ch) {
11    }
12
13    public ReadonlySequence(Sequence s)
14      : base(s) {
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      foreach (var ch in this) { h += 31 * (byte)h; }
35      return h;
36    }
37  }
38}
Note: See TracBrowser for help on using the repository browser.