Class LongList


  • public class LongList
    extends java.lang.Object
    A more efficient List<Long> using a primitive long array.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int count  
      private long[] entries  
    • Constructor Summary

      Constructors 
      Constructor Description
      LongList()
      Create an empty list with a default capacity.
      LongList​(int capacity)
      Create an empty list with the specified capacity.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(long n)
      Add an entry to the end of the list.
      void clear()
      Clear this list
      boolean contains​(long value)
      Determine if an entry appears in this collection.
      void fillTo​(int toIndex, long val)
      Pad the list with entries.
      long get​(int i)
      Get the value at the specified index
      private void grow()  
      void set​(int index, long n)
      Assign an entry in the list.
      int size()
      Get number of entries in this list
      void sort()
      Sort the list of longs according to their natural ordering.
      java.lang.String toString()
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • entries

        private long[] entries
      • count

        private int count
    • Constructor Detail

      • LongList

        public LongList()
        Create an empty list with a default capacity.
      • LongList

        public LongList​(int capacity)
        Create an empty list with the specified capacity.
        Parameters:
        capacity - number of entries the list can initially hold.
    • Method Detail

      • size

        public int size()
        Get number of entries in this list
        Returns:
        number of entries in this list
      • get

        public long get​(int i)
        Get the value at the specified index
        Parameters:
        i - index to read, must be in the range [0, size()).
        Returns:
        the number at the specified index
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - the index outside the valid range
      • contains

        public boolean contains​(long value)
        Determine if an entry appears in this collection.
        Parameters:
        value - the value to search for.
        Returns:
        true of value appears in this list.
      • clear

        public void clear()
        Clear this list
      • add

        public void add​(long n)
        Add an entry to the end of the list.
        Parameters:
        n - the number to add.
      • set

        public void set​(int index,
                        long n)
        Assign an entry in the list.
        Parameters:
        index - index to set, must be in the range [0, size()).
        n - value to store at the position.
      • fillTo

        public void fillTo​(int toIndex,
                           long val)
        Pad the list with entries.
        Parameters:
        toIndex - index position to stop filling at. 0 inserts no filler. 1 ensures the list has a size of 1, adding val if the list is currently empty.
        val - value to insert into padded positions.
      • sort

        public void sort()
        Sort the list of longs according to their natural ordering.
      • grow

        private void grow()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object