feat: fast list now implements IList

This commit is contained in:
2025-10-13 12:39:49 +03:00
parent c7d170fad9
commit a2e704916e

View File

@@ -3,14 +3,15 @@ using System.Collections.Generic;
namespace Engine.Core;
public class FastList<T> : IReadOnlyList<T>, IEnumerable<T> where T : notnull
public class FastList<T> : IList<T>, IReadOnlyList<T>, IEnumerable<T> where T : notnull
{
private readonly List<T> items = [];
private readonly Dictionary<T, int> indexMap = [];
public int Count => items.Count;
public T this[int index] => items[index];
public bool IsReadOnly { get; set; } = false;
public T this[int index] { get => items[index]; set => items[index] = value; }
public void Add(T item)
{
@@ -66,6 +67,9 @@ public class FastList<T> : IReadOnlyList<T>, IEnumerable<T> where T : notnull
indexMap[items[i]] = i;
}
public int IndexOf(T item) => items.IndexOf(item);
public void CopyTo(T[] array, int arrayIndex) => items.CopyTo(array, arrayIndex);
public IEnumerator<T> GetEnumerator() => items.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();