com.vladium.util
Class ObjectIntMap

java.lang.Object
  extended by com.vladium.util.ObjectIntMap

public final class ObjectIntMap
extends java.lang.Object

MT-safety: an instance of this class is not safe for access from multiple concurrent threads [even if access is done by a single thread at a time]. The caller is expected to synchronize externally on an instance [the implementation does not do internal synchronization for the sake of efficiency]. java.util.ConcurrentModificationException is not supported either.

Author:
(C) 2001, Vlad Roubtsov

Nested Class Summary
private static class ObjectIntMap.Entry
          The structure used for chaining colliding keys.
 
Field Summary
private static java.lang.String EOL
           
private  ObjectIntMap.Entry[] m_buckets
           
private  float m_loadFactor
           
private  int m_size
           
private  int m_sizeThreshold
           
 
Constructor Summary
ObjectIntMap()
          Equivalent to IntObjectMap(11, 0.75F).
ObjectIntMap(int initialCapacity)
          Equivalent to IntObjectMap(capacity, 0.75F).
ObjectIntMap(int initialCapacity, float loadFactor)
          Constructs an IntObjectMap with specified initial capacity and load factor.
 
Method Summary
 boolean contains(java.lang.Object key)
           
(package private)  void debugDump(java.lang.StringBuffer out)
           
 boolean get(java.lang.Object key, int[] out)
          Returns the value that is mapped to a given 'key'.
 java.lang.Object[] keys()
           
 void put(java.lang.Object key, int value)
          Updates the table to map 'key' to 'value'.
private  void rehash()
          Re-hashes the table into a new array of buckets.
 void remove(java.lang.Object key)
          Updates the table to map 'key' to 'value'.
 int size()
          Returns the number of key-value mappings in this map.
 java.lang.String toString()
          Overrides Object.toString() for debug purposes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_loadFactor

private final float m_loadFactor

m_buckets

private ObjectIntMap.Entry[] m_buckets

m_size

private int m_size

m_sizeThreshold

private int m_sizeThreshold

EOL

private static final java.lang.String EOL
Constructor Detail

ObjectIntMap

public ObjectIntMap()
Equivalent to IntObjectMap(11, 0.75F).


ObjectIntMap

public ObjectIntMap(int initialCapacity)
Equivalent to IntObjectMap(capacity, 0.75F).


ObjectIntMap

public ObjectIntMap(int initialCapacity,
                    float loadFactor)
Constructs an IntObjectMap with specified initial capacity and load factor.

Parameters:
initialCapacity - initial number of hash buckets in the table [may not be negative, 0 is equivalent to 1].
loadFactor - the load factor to use to determine rehashing points [must be in (0.0, 1.0] range].
Method Detail

toString

public java.lang.String toString()
Overrides Object.toString() for debug purposes.

Overrides:
toString in class java.lang.Object

size

public int size()
Returns the number of key-value mappings in this map.


contains

public boolean contains(java.lang.Object key)

get

public boolean get(java.lang.Object key,
                   int[] out)
Returns the value that is mapped to a given 'key'. Returns false if this key has never been mapped.

Parameters:
key - mapping key [may not be null]
out - holder for the found value [must be at least of size 1]
Returns:
'true' if this key was mapped to an existing value

keys

public java.lang.Object[] keys()

put

public void put(java.lang.Object key,
                int value)
Updates the table to map 'key' to 'value'. Any existing mapping is overwritten.

Parameters:
key - mapping key [may not be null]
value - mapping value.

remove

public void remove(java.lang.Object key)
Updates the table to map 'key' to 'value'. Any existing mapping is overwritten.

Parameters:
key - mapping key [may not be null]

debugDump

void debugDump(java.lang.StringBuffer out)

rehash

private void rehash()
Re-hashes the table into a new array of buckets.