-
Notifications
You must be signed in to change notification settings - Fork 0
/
String.cs
36 lines (31 loc) · 943 Bytes
/
String.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
namespace LCS
{
struct String : IEquatable<String>, IComparable<String>
{
public int Start;
public int Length;
public int End
{
get => Start + Length;
set => Length = value - Start;
}
public String(int start, int length)
{
Start = start;
Length = length;
}
public readonly int CompareTo(String other)
{
int c;
if ((c = other.Length - Length) != 0) return c;
return Start - other.Start;
}
public static bool operator==(String x, String y) => x.Equals(y);
public static bool operator!=(String x, String y) => !x.Equals(y);
public readonly bool Equals(String other) => Start == other.Start && Length == other.Length;
public readonly override bool Equals(object obj) => obj is String s && Equals(s);
public readonly override int GetHashCode() => Start ^ Length << 16 ^ Length >> 16;
public readonly override string ToString() => Utility.FormatRange(Start, Length);
}
}