org.aspectbench.tm.runtime.internal
Class IdentityHashMap

java.lang.Object
  extended byorg.aspectbench.tm.runtime.internal.IdentityHashMap
All Implemented Interfaces:
java.util.Map
Direct Known Subclasses:
WeakKeyCollectingIdentityHashMap, WeakKeyIdentityHashMap

public class IdentityHashMap
extends java.lang.Object
implements java.util.Map


Nested Class Summary
 
Nested classes inherited from class java.util.Map
java.util.Map.Entry
 
Field Summary
protected  org.aspectbench.tm.runtime.internal.IdentityHashMap.HashEntry[] data
          Map entries
protected static int DEFAULT_CAPACITY
          The default capacity to use
protected static float DEFAULT_LOAD_FACTOR
          The default load factor to use
protected static int DEFAULT_THRESHOLD
          The default threshold to use
protected  float loadFactor
          Load factor, normally 0.75
protected static int MAXIMUM_CAPACITY
          The maximum capacity allowed
protected  int modCount
          Modification count for iterators
protected  int size
          The size of the map
protected  int threshold
          Size at which to rehash
 
Constructor Summary
IdentityHashMap()
           
IdentityHashMap(int initialCapacity)
           
IdentityHashMap(int initialCapacity, float loadFactor)
           
IdentityHashMap(int initialCapacity, float loadFactor, int threshold)
           
 
Method Summary
protected static int calculateNewCapacity(int proposedCapacity)
          Calculates the new capacity of the map.
protected static int calculateThreshold(int newCapacity, float factor)
          Calculates the new threshold of the map, where it will be resized.
protected  void checkCapacity()
          Increases the number of buckets if necessary.
 void clear()
          
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
           
 java.util.Set entrySet()
           
 java.lang.Object get(java.lang.Object key)
          
protected  int hashIndex(java.lang.Object key)
          Calculates the hash bucket for this key.
protected  int hashIndex(java.lang.Object key, int capacity)
          Calculates the hash bucket for the given key, assuming the given number of buckets.
protected  int hashIndexFromCode(int hashCode)
          Calculates the hash bucket this hashCode should go into.
protected  int hashIndexFromCode(int hashCode, int capacity)
          Calculates the hash bucket this hashCode should go into, assuming the given number of buckets
 boolean isEmpty()
          Strictly speaking, this shoudn't be used for checking emptiness, since the intention is for subclasses to provide weak-key maps, i.e.
protected  org.aspectbench.tm.runtime.internal.IdentityHashMap.KeyIterator keyIterator()
          Constructs a KeyIterator object
 java.util.Set keySet()
          
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          
 void putAll(java.util.Map arg0)
           
protected  void rebalance(int n)
          Increases the number of buckets and re-distributes the entries into the new buckets.
 java.lang.Object remove(java.lang.Object key)
          
 int size()
          Return the number of key/value pairs in the map.
 java.util.Collection values()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

DEFAULT_CAPACITY

protected static final int DEFAULT_CAPACITY
The default capacity to use

See Also:
Constant Field Values

DEFAULT_THRESHOLD

protected static final int DEFAULT_THRESHOLD
The default threshold to use

See Also:
Constant Field Values

DEFAULT_LOAD_FACTOR

protected static final float DEFAULT_LOAD_FACTOR
The default load factor to use

See Also:
Constant Field Values

MAXIMUM_CAPACITY

protected static final int MAXIMUM_CAPACITY
The maximum capacity allowed

See Also:
Constant Field Values

loadFactor

protected transient float loadFactor
Load factor, normally 0.75


size

protected transient int size
The size of the map


data

protected transient org.aspectbench.tm.runtime.internal.IdentityHashMap.HashEntry[] data
Map entries


threshold

protected transient int threshold
Size at which to rehash


modCount

protected transient int modCount
Modification count for iterators

Constructor Detail

IdentityHashMap

public IdentityHashMap()

IdentityHashMap

public IdentityHashMap(int initialCapacity)

IdentityHashMap

public IdentityHashMap(int initialCapacity,
                       float loadFactor)

IdentityHashMap

public IdentityHashMap(int initialCapacity,
                       float loadFactor,
                       int threshold)
Method Detail

size

public int size()
Return the number of key/value pairs in the map.

Specified by:
size in interface java.util.Map

calculateNewCapacity

protected static int calculateNewCapacity(int proposedCapacity)
Calculates the new capacity of the map. This implementation normalizes the capacity to a power of two.

Parameters:
proposedCapacity - the proposed capacity
Returns:
the normalized new capacity

calculateThreshold

protected static int calculateThreshold(int newCapacity,
                                        float factor)
Calculates the new threshold of the map, where it will be resized. This implementation uses the load factor.

Parameters:
newCapacity - the new capacity
factor - the load factor
Returns:
the new resize threshold

hashIndexFromCode

protected int hashIndexFromCode(int hashCode)
Calculates the hash bucket this hashCode should go into.

Parameters:
hashCode - the pre-computed hashCode of the object
Returns:
an index into the buckets array

hashIndexFromCode

protected int hashIndexFromCode(int hashCode,
                                int capacity)
Calculates the hash bucket this hashCode should go into, assuming the given number of buckets

Parameters:
hashCode - the pre-computed hashCode of the object
capacity - the target number of buckets
Returns:
an index into the buckets array

hashIndex

protected int hashIndex(java.lang.Object key)
Calculates the hash bucket for this key.


hashIndex

protected int hashIndex(java.lang.Object key,
                        int capacity)
Calculates the hash bucket for the given key, assuming the given number of buckets.


isEmpty

public boolean isEmpty()
Strictly speaking, this shoudn't be used for checking emptiness, since the intention is for subclasses to provide weak-key maps, i.e. maps that drop a key-value pair as soon as the (weakref) key expires. Since GC runs happen beyond the control of the program, this might happen in between a call to isEmpty() and the use of the map on the assumption it's non-empty. The preferred way is creating a value iterator and using its next() method. If that returns null, then there are no more elements. It is, however, safe to assume that if this method returns true, then the map will indeed be empty until more elements are added.

Specified by:
isEmpty in interface java.util.Map

containsKey

public boolean containsKey(java.lang.Object key)
Specified by:
containsKey in interface java.util.Map

containsValue

public boolean containsValue(java.lang.Object value)
Specified by:
containsValue in interface java.util.Map

get

public java.lang.Object get(java.lang.Object key)

Specified by:
get in interface java.util.Map

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)

Specified by:
put in interface java.util.Map

checkCapacity

protected void checkCapacity()
Increases the number of buckets if necessary.


rebalance

protected void rebalance(int n)
Increases the number of buckets and re-distributes the entries into the new buckets.

Parameters:
n - the desired new number of buckets -- should be a power of 2.

remove

public java.lang.Object remove(java.lang.Object key)

Specified by:
remove in interface java.util.Map

putAll

public void putAll(java.util.Map arg0)
Specified by:
putAll in interface java.util.Map

clear

public void clear()

Specified by:
clear in interface java.util.Map

keySet

public java.util.Set keySet()

Specified by:
keySet in interface java.util.Map

keyIterator

protected org.aspectbench.tm.runtime.internal.IdentityHashMap.KeyIterator keyIterator()
Constructs a KeyIterator object


values

public java.util.Collection values()
Specified by:
values in interface java.util.Map

entrySet

public java.util.Set entrySet()
Specified by:
entrySet in interface java.util.Map