Class IntCircularQueue


  • public class IntCircularQueue
    extends Object
    A fix sized circular queue optimized for removing first and last elements. Some few (essential regarding the usage) methods are implemented.
    Be aware of the size computation: the modulo operation is not efficient in java. On the other hand, the modulo of powers of 2 can alternatively be expressed as a bitwise AND operation:
    x % 2n == x & (2n - 1)
    That is why the size of the data is automatically set to the closest greater powers of 2 value.
    Since:
    29 sept. 2010
    Author:
    Charles Prud'homme
    • Constructor Detail

      • IntCircularQueue

        public IntCircularQueue​(int size)
    • Method Detail

      • isEmpty

        public boolean isEmpty()
      • size

        public int size()
      • clear

        public void clear()
      • get

        public int get​(int index)
      • addFirst

        public boolean addFirst​(int e)
      • addLast

        public boolean addLast​(int e)
      • pollFirst

        public int pollFirst()
        This method is the main reason we re-wrote the class. It is optimized for removing first and last elements but also allows you to remove in the middle of the list.
      • pollLast

        public int pollLast()
        This method is the main reason we re-wrote the class. It is optimized for removing first and last elements but also allows you to remove in the middle of the list.