43 lines
861 B
C#
43 lines
861 B
C#
namespace Qrakhen.Qamp.Core.Collections;
|
|
|
|
public class StackLike<T> : Expander<T>,
|
|
IPush<long, T>,
|
|
IPop<T>,
|
|
ISeekable<long, T>,
|
|
IPeekable<T>
|
|
{
|
|
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<T> 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;
|
|
}
|