Class IntRangeToIntMap

  • All Implemented Interfaces:
    IntToIntMap

    public class IntRangeToIntMap
    extends java.lang.Object
    implements IntToIntMap
    Set of int values. This implementation of IntSet uses a sorted array of integer ranges.
    • Constructor Summary

      Constructors 
      Constructor Description
      IntRangeToIntMap​(int capacity)
      Create an empty map, with given initial capacity
      IntRangeToIntMap​(int[] startPoints, int[] endPoints)
      Create an IntRangeSet given the start points and end points of the integer ranges.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addEntry​(int start, int end, int value)
      Add an entry to the map.
      void clear()
      Clear the map.
      boolean contains​(int value)
      Finds whether a key is present in the map.
      int get​(int value)
      Gets the value for this key.
      int getDefaultValue()
      Get the default value used to indicate an unused entry
      int[] getEndPoints()
      Get the end points of the ranges
      int getNumberOfRanges()
      Get the number of ranges actually in use
      int[] getStartPoints()
      Get the start points of the ranges
      boolean isEmpty()  
      IntIterator keyIterator()
      Get an iterator over the integer key values held in the hash map
      void put​(int key, int value)
      Adds a key-value pair to the map.
      boolean remove​(int value)
      Removes a key from the map.
      void setDefaultValue​(int defaultValue)
      Set the value to be returned to indicate an unused entry
      int size()
      Gets the size of the map.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • IntRangeToIntMap

        public IntRangeToIntMap​(int capacity)
        Create an empty map, with given initial capacity
        Parameters:
        capacity - the initial capacity
      • IntRangeToIntMap

        public IntRangeToIntMap​(int[] startPoints,
                                int[] endPoints)
        Create an IntRangeSet given the start points and end points of the integer ranges. The two arrays must be the same length; each must be in ascending order; and the n'th end point must be greater than the n'th start point, and less than the n+1'th start point, for all n.
        Parameters:
        startPoints - the start points of the integer ranges
        endPoints - the end points of the integer ranges
        Throws:
        java.lang.IllegalArgumentException - if the two arrays are different lengths. Other error conditions in the input are not currently detected.
    • Method Detail

      • setDefaultValue

        public void setDefaultValue​(int defaultValue)
        Set the value to be returned to indicate an unused entry
        Specified by:
        setDefaultValue in interface IntToIntMap
        Parameters:
        defaultValue - the value to be returned by get(int) if no entry exists for the supplied key
      • getDefaultValue

        public int getDefaultValue()
        Get the default value used to indicate an unused entry
        Specified by:
        getDefaultValue in interface IntToIntMap
        Returns:
        the value to be returned by get(int) if no entry exists for the supplied key
      • clear

        public void clear()
        Description copied from interface: IntToIntMap
        Clear the map.
        Specified by:
        clear in interface IntToIntMap
      • size

        public int size()
        Description copied from interface: IntToIntMap
        Gets the size of the map.
        Specified by:
        size in interface IntToIntMap
        Returns:
        the size
      • isEmpty

        public boolean isEmpty()
      • contains

        public boolean contains​(int value)
        Description copied from interface: IntToIntMap
        Finds whether a key is present in the map.
        Specified by:
        contains in interface IntToIntMap
        Parameters:
        value - Key
        Returns:
        true if the key is mapped
      • get

        public int get​(int value)
        Description copied from interface: IntToIntMap
        Gets the value for this key.
        Specified by:
        get in interface IntToIntMap
        Parameters:
        value - Key
        Returns:
        the value, or the default value if not found.
      • remove

        public boolean remove​(int value)
        Description copied from interface: IntToIntMap
        Removes a key from the map.
        Specified by:
        remove in interface IntToIntMap
        Parameters:
        value - Key to remove
        Returns:
        true if the value was removed
      • addEntry

        public void addEntry​(int start,
                             int end,
                             int value)
        Add an entry to the map. Ranges of entries must be added in ascending numerical order
        Parameters:
        start - the start of the range to be added
        end - the end of the range to be added
        value - the value corresponding to this range of integer keys
      • toString

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

        public int[] getStartPoints()
        Get the start points of the ranges
        Returns:
        the start points
      • getEndPoints

        public int[] getEndPoints()
        Get the end points of the ranges
        Returns:
        the end points
      • getNumberOfRanges

        public int getNumberOfRanges()
        Get the number of ranges actually in use
        Returns:
        the number of ranges
      • put

        public void put​(int key,
                        int value)
        Adds a key-value pair to the map.
        Specified by:
        put in interface IntToIntMap
        Parameters:
        key - Key
        value - Value
      • keyIterator

        public IntIterator keyIterator()
        Get an iterator over the integer key values held in the hash map
        Specified by:
        keyIterator in interface IntToIntMap
        Returns:
        an iterator whose next() call returns the key values (in arbitrary order)