11using System.Collections;
12using System.Collections.Generic;
17 public static class ReadonlySliceExtensions {
32 public static ReadonlySlice<T> ReadonlySlice<T>(
this ReadonlyList<T> list,
int beginIdx = -1,
int endIdx = -1) {
33 if (beginIdx == -1 && endIdx == -1) {
34 return new ReadonlySlice<T>(list, 0, list.Count);
36 else if (beginIdx == -1 && endIdx != -1) {
37 return new ReadonlySlice<T>(list, 0, endIdx);
39 else if (endIdx == -1 && beginIdx != -1) {
40 return new ReadonlySlice<T>(list, beginIdx, list.Count);
43 return new ReadonlySlice<T>(list, beginIdx, endIdx);
47 public static ReadonlySlice<T> FromIndex<T>(
this ReadonlyList<T> list,
int fromIdx) {
48 return ReadonlySlice(list, fromIdx);
57 private int _beginIdx;
60 private int _direction;
73 _direction = beginIdx <= endIdx ? 1 : -1;
76 public T
this[
int index] {
78 if (index < 0 || index >
Count - 1) {
throw new IndexOutOfRangeException(); }
79 return _list[_beginIdx + index * _direction];
85 return (_endIdx - _beginIdx) * _direction;
89 #region foreach and Query()
96 T[] array = ArrayPool<T>.Spawn(
Count);
97 for (
int i = 0; i <
Count; i++) {
This is a definition-friendly interface that new "indexable" struct definitions can implement to make...
A two-generic-argument variant of an enumerator that allows an IIndexableStruct to quickly define an ...
A Query object is a type of immutable ordered collection of elements that can be used to perform usef...
A simple wrapper around List to provide readonly access. Useful when you want to return a list to som...
ReadonlySlice(ReadonlyList< T > list, int beginIdx, int endIdx)
Creates a readonlySlice into the ReadonlyList with an inclusive beginIdx and an exclusive endIdx....
IndexableStructEnumerator< T, ReadonlySlice< T > > GetEnumerator()