Skip to content

Commit c0af77c

Browse files
committed
Closes #6
1 parent e8252c9 commit c0af77c

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

Segments/Segment.cs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
using System;
22
using System.Collections;
33
using System.Collections.Generic;
4+
using Platform.Collections.Lists;
45

56
namespace Platform.Collections.Segments
67
{
78
public class Segment<T> : IEquatable<Segment<T>>, IList<T>
89
{
9-
private static readonly EqualityComparer<T> EqualityComparer = EqualityComparer<T>.Default;
10-
1110
public readonly IList<T> Base;
1211
public readonly int Offset;
1312
public readonly int Length;
@@ -19,12 +18,6 @@ public Segment(IList<T> @base, int offset, int length)
1918
Length = length;
2019
}
2120

22-
public T this[int i]
23-
{
24-
get => Base[Offset + i];
25-
set => Base[Offset + i] = value;
26-
}
27-
2821
/// <remarks>
2922
/// Based on https://github.com/Microsoft/referencesource/blob/3b1eaf5203992df69de44c783a3eda37d3d4cd10/mscorlib/system/string.cs#L833
3023
/// </remarks>
@@ -39,20 +32,18 @@ public override int GetHashCode()
3932
return hashAccumulator + (hashSeed * 1566083941);
4033
}
4134

42-
public virtual bool Equals(Segment<T> other)
43-
{
44-
if (Length != other.Length) return false;
45-
46-
for (var i = 0; i < Length; i++)
47-
if (!EqualityComparer.Equals(this[i], other[i]))
48-
return false;
49-
return true;
50-
}
35+
public virtual bool Equals(Segment<T> other) => other.EqualTo(this);
5136

5237
public override bool Equals(object obj) => obj is Segment<T> other ? Equals(other) : false;
5338

5439
#region IList
5540

41+
public T this[int i]
42+
{
43+
get => Base[Offset + i];
44+
set => Base[Offset + i] = value;
45+
}
46+
5647
public int Count => Length;
5748

5849
public bool IsReadOnly => true;

0 commit comments

Comments
 (0)