refactor: auto property on FastListOrdered
This commit is contained in:
@@ -16,8 +16,7 @@ public class FastListOrdered<TIndex, TItem> : IList<TItem>, IReadOnlyList<TItem>
|
|||||||
private readonly Func<TItem, TIndex> getIndexFunc = null!;
|
private readonly Func<TItem, TIndex> getIndexFunc = null!;
|
||||||
private readonly IComparer<TIndex> sortBy = null!;
|
private readonly IComparer<TIndex> sortBy = null!;
|
||||||
|
|
||||||
private int count = 0;
|
public int Count { get; private set; } = 0;
|
||||||
public int Count => count;
|
|
||||||
|
|
||||||
public bool IsReadOnly { get; set; } = false;
|
public bool IsReadOnly { get; set; } = false;
|
||||||
|
|
||||||
@@ -35,10 +34,10 @@ public class FastListOrdered<TIndex, TItem> : IList<TItem>, IReadOnlyList<TItem>
|
|||||||
private (TIndex TIndex, int i) GetAt(Index index)
|
private (TIndex TIndex, int i) GetAt(Index index)
|
||||||
{
|
{
|
||||||
int actualIndex = index.IsFromEnd
|
int actualIndex = index.IsFromEnd
|
||||||
? count - index.Value
|
? Count - index.Value
|
||||||
: index.Value;
|
: index.Value;
|
||||||
|
|
||||||
if (actualIndex < 0 || actualIndex >= count)
|
if (actualIndex < 0 || actualIndex >= Count)
|
||||||
throw new IndexOutOfRangeException();
|
throw new IndexOutOfRangeException();
|
||||||
|
|
||||||
int leftIndex = actualIndex;
|
int leftIndex = actualIndex;
|
||||||
@@ -75,7 +74,7 @@ public class FastListOrdered<TIndex, TItem> : IList<TItem>, IReadOnlyList<TItem>
|
|||||||
items[key] = list = [];
|
items[key] = list = [];
|
||||||
|
|
||||||
list.Add(item);
|
list.Add(item);
|
||||||
count++;
|
Count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Insert(int index, TItem item)
|
public void Insert(int index, TItem item)
|
||||||
@@ -88,7 +87,7 @@ public class FastListOrdered<TIndex, TItem> : IList<TItem>, IReadOnlyList<TItem>
|
|||||||
items[tIndex] = list = [];
|
items[tIndex] = list = [];
|
||||||
|
|
||||||
list.Insert(index, item);
|
list.Insert(index, item);
|
||||||
count++;
|
Count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Remove(TItem item)
|
public bool Remove(TItem item)
|
||||||
@@ -103,7 +102,7 @@ public class FastListOrdered<TIndex, TItem> : IList<TItem>, IReadOnlyList<TItem>
|
|||||||
if (!list.Remove(item))
|
if (!list.Remove(item))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
count--;
|
Count--;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,7 +113,7 @@ public class FastListOrdered<TIndex, TItem> : IList<TItem>, IReadOnlyList<TItem>
|
|||||||
|
|
||||||
(TIndex tIndex, int i) = GetAt(index);
|
(TIndex tIndex, int i) = GetAt(index);
|
||||||
items[tIndex].RemoveAt(i);
|
items[tIndex].RemoveAt(i);
|
||||||
count--;
|
Count--;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Clear()
|
public void Clear()
|
||||||
@@ -125,7 +124,7 @@ public class FastListOrdered<TIndex, TItem> : IList<TItem>, IReadOnlyList<TItem>
|
|||||||
foreach ((TIndex index, FastList<TItem> list) in items)
|
foreach ((TIndex index, FastList<TItem> list) in items)
|
||||||
list.Clear();
|
list.Clear();
|
||||||
|
|
||||||
count = 0;
|
Count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Contains(TItem item)
|
public bool Contains(TItem item)
|
||||||
|
|||||||
Reference in New Issue
Block a user