#if !USE_DYNAMIC_STACKS using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace MoonSharp.Interpreter.DataStructs { public class FastStack : IList { T[] m_Storage; int m_HeadIdx = 0; public FastStack(int maxCapacity) { m_Storage = new T[maxCapacity]; } public T this[int index] { get { return m_Storage[index]; } set { m_Storage[index] = value; } } public T Push(T item) { m_Storage[m_HeadIdx++] = item; return item; } public void Expand(int size) { m_HeadIdx += size; } private void Zero(int from, int to) { Array.Clear(m_Storage, from, to - from + 1); } private void Zero(int index) { m_Storage[index] = default(T); } public T Peek(int idxofs = 0) { T item = m_Storage[m_HeadIdx - 1 - idxofs]; return item; } public void CropAtCount(int p) { RemoveLast(Count - p); } public void RemoveLast( int cnt = 1) { if (cnt == 1) { --m_HeadIdx; m_Storage[m_HeadIdx] = default(T); } else { int oldhead = m_HeadIdx; m_HeadIdx -= cnt; Zero(m_HeadIdx, oldhead); } } public T Pop() { --m_HeadIdx; T retval = m_Storage[m_HeadIdx]; m_Storage[m_HeadIdx] = default(T); return retval; } public void Clear() { Array.Clear(m_Storage, 0, m_Storage.Length); m_HeadIdx = 0; } public int Count { get { return m_HeadIdx; } } #region IList Impl. int IList.IndexOf(T item) { throw new NotImplementedException(); } void IList.Insert(int index, T item) { throw new NotImplementedException(); } void IList.RemoveAt(int index) { throw new NotImplementedException(); } T IList.this[int index] { get { return this[index]; } set { this[index] = value; } } void ICollection.Add(T item) { Push(item); } void ICollection.Clear() { Clear(); } bool ICollection.Contains(T item) { throw new NotImplementedException(); } void ICollection.CopyTo(T[] array, int arrayIndex) { throw new NotImplementedException(); } int ICollection.Count { get { return this.Count; } } bool ICollection.IsReadOnly { get { return false; } } bool ICollection.Remove(T item) { throw new NotImplementedException(); } IEnumerator IEnumerable.GetEnumerator() { throw new NotImplementedException(); } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw new NotImplementedException(); } #endregion } } #endif