jdbm.helper
Class LongHashMap<V>

java.lang.Object
  extended by jdbm.helper.LongHashMap<V>
All Implemented Interfaces:
java.io.Serializable

public class LongHashMap<V>
extends java.lang.Object
implements java.io.Serializable

Hash Map which uses primitive long as key. Main advantage is new instanceof of Long does not have to be created for each lookup.

This code comes from Android, which in turns comes to Apache Harmony. This class was modified to use primitive longs and stripped down to consume less space.

Author of JDBM modifications: Jan Kotek

Note: This map have weakened hash function, this works well for JDBM, but may be wrong for many other applications.

See Also:
Serialized Form

Constructor Summary
LongHashMap()
          Constructs a new empty HashMap instance.
LongHashMap(int capacity)
          Constructs a new HashMap instance with the specified capacity.
LongHashMap(int capacity, float loadFactor)
          Constructs a new HashMap instance with the specified capacity and load factor.
 
Method Summary
 void clear()
          Removes all mappings from this hash map, leaving it empty.
 boolean containsKey(long key)
          Returns whether this map contains the specified key.
 boolean containsValue(java.lang.Object value)
          Returns whether this map contains the specified value.
 V get(long key)
          Returns the value of the mapping with the specified key.
 boolean isEmpty()
          Returns whether this map is empty.
 V put(long key, V value)
          Maps the specified key to the specified value.
 V remove(long key)
          Removes the mapping with the specified key from this map.
 int size()
          Returns the number of elements in this map.
 java.util.Iterator<V> valuesIterator()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LongHashMap

public LongHashMap()
Constructs a new empty HashMap instance.

Since:
Android 1.0

LongHashMap

public LongHashMap(int capacity)
Constructs a new HashMap instance with the specified capacity.

Parameters:
capacity - the initial capacity of this hash map.
Throws:
java.lang.IllegalArgumentException - when the capacity is less than zero.
Since:
Android 1.0

LongHashMap

public LongHashMap(int capacity,
                   float loadFactor)
Constructs a new HashMap instance with the specified capacity and load factor.

Parameters:
capacity - the initial capacity of this hash map.
loadFactor - the initial load factor.
Throws:
java.lang.IllegalArgumentException - when the capacity is less than zero or the load factor is less or equal to zero.
Since:
Android 1.0
Method Detail

clear

public void clear()
Removes all mappings from this hash map, leaving it empty.

Since:
Android 1.0
See Also:
isEmpty(), size()

containsKey

public boolean containsKey(long key)
Returns whether this map contains the specified key.

Parameters:
key - the key to search for.
Returns:
true if this map contains the specified key, false otherwise.
Since:
Android 1.0

containsValue

public boolean containsValue(java.lang.Object value)
Returns whether this map contains the specified value.

Parameters:
value - the value to search for.
Returns:
true if this map contains the specified value, false otherwise.
Since:
Android 1.0

get

public V get(long key)
Returns the value of the mapping with the specified key.

Parameters:
key - the key.
Returns:
the value of the mapping with the specified key, or null if no mapping for the specified key is found.
Since:
Android 1.0

isEmpty

public boolean isEmpty()
Returns whether this map is empty.

Returns:
true if this map has no elements, false otherwise.
Since:
Android 1.0
See Also:
size()

put

public V put(long key,
             V value)
Maps the specified key to the specified value.

Parameters:
key - the key.
value - the value.
Returns:
the value of any previous mapping with the specified key or null if there was no such mapping.
Since:
Android 1.0

remove

public V remove(long key)
Removes the mapping with the specified key from this map.

Parameters:
key - the key of the mapping to remove.
Returns:
the value of the removed mapping or null if no mapping for the specified key was found.
Since:
Android 1.0

size

public int size()
Returns the number of elements in this map.

Returns:
the number of elements in this map.
Since:
Android 1.0

valuesIterator

public java.util.Iterator<V> valuesIterator()


Cees de Groot (C) 2000. All rights reserved http://jdbm.sourceforge.net