Package org.h2.util

Class SmallMap


  • public class SmallMap
    extends java.lang.Object
    A simple hash table with an optimization for the last recently used object.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.Object cache  
      private int cacheId  
      private int lastId  
      private java.util.HashMap<java.lang.Integer,​java.lang.Object> map  
      private int maxElements  
    • Constructor Summary

      Constructors 
      Constructor Description
      SmallMap​(int maxElements)
      Create a map with the given maximum number of entries.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int addObject​(int id, java.lang.Object o)
      Add an object to the map.
      void freeObject​(int id)
      Remove an object from the map.
      java.lang.Object getObject​(int id, boolean ifAvailable)
      Get an object from the map if it is stored.
      • Methods inherited from class java.lang.Object

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

      • map

        private final java.util.HashMap<java.lang.Integer,​java.lang.Object> map
      • cache

        private java.lang.Object cache
      • cacheId

        private int cacheId
      • lastId

        private int lastId
      • maxElements

        private final int maxElements
    • Constructor Detail

      • SmallMap

        public SmallMap​(int maxElements)
        Create a map with the given maximum number of entries.
        Parameters:
        maxElements - the maximum number of entries
    • Method Detail

      • addObject

        public int addObject​(int id,
                             java.lang.Object o)
        Add an object to the map. If the size of the map is larger than twice the maximum size, objects with a low id are removed.
        Parameters:
        id - the object id
        o - the object
        Returns:
        the id
      • freeObject

        public void freeObject​(int id)
        Remove an object from the map.
        Parameters:
        id - the id of the object to remove
      • getObject

        public java.lang.Object getObject​(int id,
                                          boolean ifAvailable)
        Get an object from the map if it is stored.
        Parameters:
        id - the id of the object
        ifAvailable - only return it if available, otherwise return null
        Returns:
        the object or null
        Throws:
        DbException - if isAvailable is false and the object has not been found