Skip to content
Snippets Groups Projects
Select Git revision
  • d6b9518be83ff0cb37015399ada1691f3c8b24a0
  • master default
  • simulated_grasping
  • v1.0
4 results

SampleTimedCartesianPlanner.cpp

Blame
  • Lifo.cs 1.09 KiB
    using System.Collections.Generic;
    using System.Linq;
    
    namespace Hyper.PCAAprilTag
    {
        /// <summary>
        /// LIFO (Last-In-First-Out) List
        /// </summary>
        /// <typeparam name="T"></typeparam>
        public class Lifo<T>
        {
            private readonly int _capacity;
            private readonly List<T> _list;
    
            public Lifo(int capacity)
            {
                _capacity = capacity;
                _list = new List<T>(capacity);
            }
    
            public void Push(T item)
            {
                if (_list.Count >= _capacity)
                {
                    _list.RemoveAt(0);
                }
    
                _list.Add(item);
            }
    
            public T Pop()
            {
                if (_list.Count == 0) return default;
    
                var item = _list[0];
                _list.RemoveAt(0);
                return item;
            }
    
            public T Top => _list.Last();
    
            public T this[int index] => _list[index];
    
            public bool IsEmpty => _list.Count == 0;
    
            public bool IsFull => _list.Count >= _capacity;
    
            public int Count => _list.Count;
    
            public List<T> ToList() => new List<T>(_list);
        }
    }