|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectde.enough.polish.util.OAIdentityHashMap
public class OAIdentityHashMap
Provides the functionality of the J2SE java.util.HashMap for J2ME applications that uses Open Addressing for resolving collision.
WARNING 1: This Open Addressing HashMap does not support remove() operations! A RuntimeException will be thrown when remove is used. Clearing of the entire map is supported.
WARNING 2: Keys and values are compared using their references (==), so you need to ensure that you use only the original keys for retrieval of the stored values.
This implementation uses Open Addressing for resolving collision that occur when several (different) keys share the same hash code. In that case the key-value pair will be stored in the next free slot. There are different probing strategies for finding the next free slot:
In contrast to the java.util.Hashtable (which is available on J2ME platforms), this implementation is not synchronized and faster.
The default capacity is 17 for reducing possible collision. Feel free to use another prime number instead (like 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113). When you use a power of 2 for the initial capacity (like 16, 32, 64 and so on), no modulo operations need to be done, which might be beneficial depending on the hash codes of your keys.
Copyright (c) Enough Software 2005 - 2009
history
30-Nov-2005 - rob creation
| Field Summary | |
|---|---|
static int |
DEFAULT_INITIAL_CAPACITY
The default capacity is 17 |
static int |
DEFAULT_LOAD_FACTOR
The default load factor is 60, so the HashMap is increased when 60% of it's capacity is reached |
static int |
PROBING_DOUBLE_HASHING
When this probing is used, the interval between probes is fixed but calculated using another hash function. |
static int |
PROBING_LINEAR
When this probing is used, the next free slot will be used for keys that have the same hash code as a previously inserted item. |
static int |
PROBING_QUADRACTIC
When this probing is used, the interval between probes increases linearly. |
| Constructor Summary | |
|---|---|
OAIdentityHashMap()
Creates a new HashMap with the default initial capacity 17, a load factor of 60% and linear probing. |
|
OAIdentityHashMap(int initialCapacity)
Creates a new HashMap with the specified initial capacity, a load factor of 60% and linear probing. |
|
OAIdentityHashMap(int initialCapacity,
int loadFactor)
Creates a new AOHashMap with the specified initial capacity, the specified load factor and linear probing. |
|
OAIdentityHashMap(int initialCapacity,
int loadFactor,
int probingStrategy)
Creates a new AOHashMap with the specified initial capacity, the specified load factor and the specified probing strategy. |
|
| Method Summary | |
|---|---|
void |
clear()
Removes all elements from this map. |
boolean |
containsKey(Object key)
Checks if a value has been stored in this map. |
boolean |
containsValue(Object value)
Checks the given value has been stored in this map. |
Object |
get(Object key)
Gets the value that has been stored for the specified key. |
boolean |
isEmpty()
Determines whether this map is empty. |
Object[] |
keys()
Retrieves all keys that have been stored in this map. |
Object[] |
keys(Object[] objects)
Retrieves all keys that have been stored in this map. |
Iterator |
keysIterator()
Iterates over the keys of this map. |
Object |
put(Object key,
Object value)
Adds a key-value pair to this map. |
Object |
remove(Object key)
Remove is not supported by the Open Addressing HashMap. |
int |
size()
The size of this map. |
String |
toString()
Returns String containing the String representations of all objects of this map. |
Object[] |
values()
Retrieves all values that have been stored in this map. |
Object[] |
values(Object[] objects)
Retrieves all values that have been stored in this map. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int DEFAULT_INITIAL_CAPACITY
public static final int DEFAULT_LOAD_FACTOR
public static final int PROBING_LINEAR
public static final int PROBING_QUADRACTIC
public static final int PROBING_DOUBLE_HASHING
| Constructor Detail |
|---|
public OAIdentityHashMap()
public OAIdentityHashMap(int initialCapacity)
initialCapacity - the initial size of the map, remember that the default load factor
is 75%, you if you know the maximum size ahead of time, you need to calculate
initialCapacity=maxSize * 4 / 3, when you use this constructor.
public OAIdentityHashMap(int initialCapacity,
int loadFactor)
initialCapacity - the initial size of the map.loadFactor - the loadfactor in percent, a number between 0 and 100. When the loadfactor is 100,
the size of this map is only increased after all slots have been filled.
public OAIdentityHashMap(int initialCapacity,
int loadFactor,
int probingStrategy)
initialCapacity - the initial size of the map.loadFactor - the loadfactor in percent, a number between 0 and 100. When the loadfactor is 100,
the size of this map is only increased after all slots have been filled.probingStrategy - the probing strategy, either linear, quadratic or double hashing.PROBING_LINEAR,
PROBING_QUADRACTIC,
PROBING_DOUBLE_HASHING| Method Detail |
|---|
public Object put(Object key,
Object value)
Map
put in interface Mapkey - the keyvalue - the value
public Object get(Object key)
Map
get in interface Mapkey - the key
public Object remove(Object key)
remove in interface Mapkey - the key of the value to remove
RuntimeException - alwayspublic boolean isEmpty()
Map
isEmpty in interface Mappublic int size()
Map
size in interface Mappublic boolean containsKey(Object key)
Map
containsKey in interface Mapkey - the key
public boolean containsValue(Object value)
Map
containsValue in interface Mapvalue - the value
public void clear()
Map
clear in interface Mappublic Object[] values()
Map
values in interface Mappublic Object[] values(Object[] objects)
Map
values in interface Mapobjects - the typed array in which the elements are stored
public Object[] keys()
Map
keys in interface Mappublic Object[] keys(Object[] objects)
Map
keys in interface Mapobjects - the typed array in which the keys are stored
public String toString()
toString in class Objectpublic Iterator keysIterator()
Map
keysIterator in interface Map
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||