qamp/Qrakhen.Qamp.Core/Collections/FixedArray.cs

41 lines
914 B
C#

using System.Collections;
namespace Qrakhen.Qamp.Core.Collections;
/// <summary>
/// Basically just a normal array, but implements <see cref="IGetSet{TKey, TValue}"/> to be used with <see cref="Pointer{T}"/>.
/// </summary>
/// <typeparam name="T"></typeparam>
public class FixedArray<T> : IEnumerable<T>, IGetSet<long, T>
{
protected T[] Data;
public long Length => Data.LongLength;
public T this[long index] {
get => Get(index);
set => Set(index, value);
}
public FixedArray(IEnumerable<T> data)
{
Data = data.ToArray();
}
public T Get(long index) => Data[index];
public void Set(long index, T value)
{
Data[index] = value;
}
public IEnumerator<T> GetEnumerator()
{
foreach (var item in Data)
yield return item;
}
IEnumerator IEnumerable.GetEnumerator()
=> GetEnumerator();
}