Package org.h2.util
Class SmallMap
java.lang.Object
org.h2.util.SmallMap
A simple hash table with an optimization for the last recently used object.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSmallMap
(int maxElements) Create a map with the given maximum number of entries. -
Method Summary
Modifier and TypeMethodDescriptionint
Add an object to the map.void
freeObject
(int id) Remove an object from the map.getObject
(int id, boolean ifAvailable) Get an object from the map if it is stored.
-
Field Details
-
map
-
cache
-
cacheId
private int cacheId -
lastId
private int lastId -
maxElements
private final int maxElements
-
-
Constructor Details
-
SmallMap
public SmallMap(int maxElements) Create a map with the given maximum number of entries.- Parameters:
maxElements
- the maximum number of entries
-
-
Method Details
-
addObject
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 ido
- 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
Get an object from the map if it is stored.- Parameters:
id
- the id of the objectifAvailable
- 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
-