Class SortedIntArray

    • Field Detail

      • DEFAULT_CAPACITY

        public static int DEFAULT_CAPACITY
    • Constructor Detail

      • SortedIntArray

        public SortedIntArray()
        Creates a sorted int array with a default initial capacity
      • SortedIntArray

        public SortedIntArray​(int capacity)
        Creates a sorted int array with a given initial capacity
        Parameters:
        capacity -
      • SortedIntArray

        public SortedIntArray​(int... array)
        Creates the SortedIntArray by copying all values from the input array and sorting them
        Parameters:
        array -
    • Method Detail

      • insert

        public int insert​(int x)
        Inserts value to the array and return the position on which has been inserted
        Parameters:
        x - - value to be inserted
        Returns:
        the position on which the value has been inserted
      • search

        public int search​(int x)
        performs a binary search in the array.
        Parameters:
        x -
        Returns:
        result of the binarySearch, @see java.util.Arrays#binarySearch(int[], int)
        See Also:
        Arrays.binarySearch(int[], int)
      • get

        public int get​(int pos)
        get element at position
        Parameters:
        pos -
        Returns:
        the element at position
      • isEmpty

        public boolean isEmpty()
      • getArray

        public int[] getArray()
      • size

        public int size()
      • getAscendingIterator

        public PrimitiveIterator.OfInt getAscendingIterator​(int startFrom)
        Constructs an ascending iterator starting from a specified value (inclusive)
        Parameters:
        startFrom -
        Returns:
        an iterator starting from the specified value
      • getDescendingIterator

        public PrimitiveIterator.OfInt getDescendingIterator​(int startFrom)
        Constructs an descending iterator starting from a specified value (exclusive)
        Parameters:
        startFrom -
        Returns:
        an descending iterator starting from the specified value
      • forEach

        public void forEach​(IntConsumer action)
      • contains

        public boolean contains​(int x)
        Performs a binary search and returns true if this array contains the value.
        Parameters:
        x - - value to check
        Returns:
        true of the array contains the specified value
      • decodeFromVarIntArray

        public static SortedIntArray decodeFromVarIntArray​(byte[] buf)
      • add

        public void add​(int x)
        Change the elements of the array by adding x to each element
        Parameters:
        x -
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object