Class IntToIntMap


  • public class IntToIntMap
    extends java.lang.Object
    This is a map that maps from int to int. All non-existent mappings automatically map onto -1 - inserting a mapping merely redefines the mapping. This class is designed to use as little RAM as possible, and assumes that the mappings are from reasonably closely-spaced ints. In the case where the mappings are from consecutive ints, this class will use not much more than four bytes per mapping.
    Author:
    Matthew Wakeling
    • Constructor Summary

      Constructors 
      Constructor Description
      IntToIntMap()
      Constructor for this class.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Removes all mappings from the object.
      int get​(int from)
      Retrieves a mapping from the object
      java.lang.Integer get​(java.lang.Integer from)
      Retrieves a mapping from the object.
      void put​(int from, int to)
      Creates a mapping in the object.
      void put​(java.lang.Integer from, java.lang.Integer to)
      Puts a mapping in the object.
      int size()
      Returns the number of mappings to non-minus-one ints present.
      java.lang.String toString()
      • Methods inherited from class java.lang.Object

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

      • IntToIntMap

        public IntToIntMap()
        Constructor for this class. Creates an empty map.
    • Method Detail

      • put

        public void put​(int from,
                        int to)
        Creates a mapping in the object.
        Parameters:
        from - any int
        to - any int - or -1 to effectively remove the mapping
      • get

        public int get​(int from)
        Retrieves a mapping from the object
        Parameters:
        from - any int
        Returns:
        an int - -1 if there is no mapping present that matches
      • put

        public void put​(java.lang.Integer from,
                        java.lang.Integer to)
        Puts a mapping in the object.
        Parameters:
        from - an Integer
        to - any Integer other than -1, or null to remove a mapping
      • get

        public java.lang.Integer get​(java.lang.Integer from)
        Retrieves a mapping from the object.
        Parameters:
        from - any Integer
        Returns:
        an Integer other than -1, or null if there is no mapping that matches
      • size

        public int size()
        Returns the number of mappings to non-minus-one ints present.
        Returns:
        the size
      • clear

        public void clear()
        Removes all mappings from the object.
      • toString

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