Top Description Fields Constructors Methods
org.h2.util

public Class SmallMap

extends Object
Class Inheritance
Imports
java.util.HashMap, .Iterator, org.h2.api.ErrorCode, org.h2.message.DbException

A simple hash table with an optimization for the last recently used object.

Field Summary

Modifier and TypeField and Description
private Object
private int
private int
private final HashMap<Integer, Object>
private final int

Constructor Summary

AccessConstructor and Description
public
SmallMap(int
the maximum number of entries
maxElements
)

Create a map with the given maximum number of entries.

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

the id
addObject
(int
the object id
id
,
Object
the object
o
)

Add an object to the map.

public void
freeObject(int
the id of the object to remove
id
)

Remove an object from the map.

public Object

Returns:

the object or null
getObject
(int
the id of the object
id
,
boolean
only return it if available, otherwise return null
ifAvailable
)

Get an object from the map if it is stored.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cacheback to summary
private Object cache
cacheIdback to summary
private int cacheId
lastIdback to summary
private int lastId
mapback to summary
private final HashMap<Integer, Object> map
maxElementsback to summary
private final int maxElements

Constructor Detail

SmallMapback to summary
public SmallMap(int maxElements)

Create a map with the given maximum number of entries.

Parameters
maxElements:int

the maximum number of entries

Method Detail

addObjectback to summary
public int addObject(int id, 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:int

the object id

o:Object

the object

Returns:int

the id

freeObjectback to summary
public void freeObject(int id)

Remove an object from the map.

Parameters
id:int

the id of the object to remove

getObjectback to summary
public Object getObject(int id, boolean ifAvailable)

Get an object from the map if it is stored.

Parameters
id:int

the id of the object

ifAvailable:boolean

only return it if available, otherwise return null

Returns:Object

the object or null

Exceptions
DbException:
if isAvailable is false and the object has not been found