8 public class Fifo<T> : IDisposable {
9 private T[] stack =
new T[8];
13 private void DeactivateItem() => pointer = 0;
23 public T
this[
int i] => stack[i];
26 public int Count {
get => pointer;
set => pointer = value < pointer ? value : pointer; }
33 public virtual T
Push(T entry) {
34 if (pointer >= stack.Length) Array.Resize(ref stack, stack.Length * 2);
35 stack[pointer++] = entry;
42 public virtual T
Pop() => pointer == 0 ? default : stack[--pointer];
44 private static int nextId;
45 private readonly
int id = ++nextId;
59 public T
Top {
get =>
Empty ? default : stack[pointer - 1];
set => stack[pointer - 1] = value; }
62 public T
Next {
get => stack[pointer - 2];
set => stack[pointer - 2] = value; }
65 public T
Bottom {
get =>
Empty ? default : stack[0];
set => stack[0] = value; }
75 for (var i = 0; i < pointer; i++) (stack[i] as IDisposable)?.Dispose();
81 Array.Resize(ref stack, pointer);
86 public override string ToString() => $
"{typeof(T)}-{id}:{pointer}";
static Fifo< T > Instance
Fetch Fifo Stack from recycling
Fifo()
Raw creation for subclasses that do their own caching
virtual T Push(T entry)
Push a new entry onto the top of the stack
override string ToString()
//#TBD#//
Intentionally simple stack implementation
virtual void Dispose()
Send back to recycling
T Top
Get/set the value at the top of the stack.
virtual T Pop()
Pop an entry from the top of the stack
Fifo< T > Swap()
Swap the top and second entries on the stack
int Count
Number of items on the stack
T Bottom
Get/set the value at the bottom of the stack.
T Next
Get/set the value at second to top of the stack.