-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathArray.cs
56 lines (46 loc) · 1.34 KB
/
Array.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System.Collections;
using System.Runtime.CompilerServices;
using static System.Runtime.CompilerServices.MethodImplOptions;
namespace Plato
{
public readonly struct Array<T> : IArray<T>
{
public readonly Func<Integer, T> Func;
public readonly Integer Count;
[MethodImpl(AggressiveInlining)]
public Array(Integer count, Func<Integer, T> func)
{
Func = func;
Count = count;
}
[MethodImpl(AggressiveInlining)]
public T At(Integer index)
=> Func(index);
T IReadOnlyList<T>.this[int index]
{
[MethodImpl(AggressiveInlining)]
get => At(index);
}
T IArray<T>.this[Integer index]
{
[MethodImpl(AggressiveInlining)]
get => Func(index);
}
Integer IArray<T>.Count
{
[MethodImpl(AggressiveInlining)]
get => Count;
}
int IReadOnlyCollection<T>.Count
{
[MethodImpl(AggressiveInlining)]
get => Count;
}
[MethodImpl(AggressiveInlining)]
public IEnumerator<T> GetEnumerator()
=> new ArrayEnumerator<T>(this);
[MethodImpl(AggressiveInlining)]
IEnumerator IEnumerable.GetEnumerator()
=> GetEnumerator();
}
}