namespace Qrakhen.Qamp.Core.Collections; /// /// Stack-like implementation with a few added features like seeking and setting values. /// /// public class StackLike : Expander, IPush, IPop, ISeekable, IPeekable, IToArray { public long Position => Count; public T this[int position] { get => Data[position]; set => Data[position] = value; } public StackLike(int capacity = 0x10) { Data = new T[capacity]; Count = 0; } public StackLike(IEnumerable data) { Data = data.ToArray(); Count = 0; } public long Push(T value) => Add(value); public T Pop() => Data[--Count]; public T Seek(long position) { Count = position; return this[Count]; } public T Peek(int delta = -1) => Data[Count + delta]; public bool CanPeek(int delta = 0) => Count + delta > -1 && Count + delta < Count; /// /// Decimates this stack down to the given position, overwriting everything beyond that when pushing in the future. /// public void Decimate(long position) { Count = position; } public T[] ToArray() => Data.ToArray(); }