APIdia Launch Partner
Top Description Fields Constructors Methods
sun.util

public abstract Class PreHashedMap<V>

extends AbstractMap<String, V>
Class Inheritance
Known Direct Subclasses
sun.nio.cs.StandardCharsets.Aliases, sun.nio.cs.StandardCharsets.Classes, sun.nio.cs.StandardCharsets.Cache
Imports
java.util.Iterator, .Map, .Set, .AbstractMap, .AbstractSet, .NoSuchElementException

A precomputed hash map.

Subclasses of this class are of the following form:

class FooMap
    extends sun.util.PreHashedMap<String>
{

    private FooMap() {
        super(ROWS, SIZE, SHIFT, MASK);
    }

    protected void init(Object[] ht) {
        ht[0] = new Object[] { "key-1", value_1 };
        ht[1] = new Object[] { "key-2", value_2,
                     new Object { "key-3", value_3 } };
        ...
    }

}

The init method is invoked by the PreHashedMap constructor with an object array long enough for the map's rows. The method must construct the hash chain for each row and store it in the appropriate element of the array.

Each entry in the map is represented by a unique hash-chain node. The final node of a hash chain is a two-element object array whose first element is the entry's key and whose second element is the entry's value. A non-final node of a hash chain is a three-element object array whose first two elements are the entry's key and value and whose third element is the next node in the chain.

Instances of this class are mutable and are not safe for concurrent access. They may be made immutable and thread-safe via the appropriate methods in the java.util.Collections utility class.

In the JDK build, subclasses of this class are typically created via the Hasher program in the make/tools/Hasher directory.

Author
Mark Reinhold
Since
1.5
See Also
java.util.AbstractMap

Field Summary

Modifier and TypeField and Description
private final Object[]
private final int
private final int
private final int
private final int

Constructor Summary

AccessConstructor and Description
protected
PreHashedMap(int
The number of rows in the map
rows
,
int
The number of entries in the map
size
,
int
The value by which hash codes are right-shifted
shift
,
int
The value with which hash codes are masked after being shifted
mask
)

Creates a new map.

Method Summary

Modifier and TypeMethod and Description
public Set<Map.Entry<String, V>>
entrySet()

Implements abstract java.util.AbstractMap.entrySet.

Implements java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map.

public V
get(Object k)

Overrides java.util.AbstractMap.get.

Implements java.util.Map.get.

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

protected abstract void
init(Object[]
The row array to be initialized
ht
)

Initializes this map.

public Set<String>
keySet()

Overrides java.util.AbstractMap.keySet.

Implements java.util.Map.keySet.

Returns a Set view of the keys contained in this map.

public V
put(String k, V v)

Overrides java.util.AbstractMap.put.

Implements java.util.Map.put.

Associates the specified value with the specified key in this map (optional operation).

private V
Inherited from java.util.AbstractMap:
clearclonecontainsKeycontainsValueequalshashCodeisEmptyputAllremovesizetoStringvalues

Field Detail

htback to summary
private final Object[] ht
maskback to summary
private final int mask
rowsback to summary
private final int rows
shiftback to summary
private final int shift
sizeback to summary
private final int size

Constructor Detail

PreHashedMapback to summary
protected PreHashedMap(int rows, int size, int shift, int mask)

Creates a new map.

This constructor invokes the init method, passing it a newly-constructed row array that is rows elements long.

Parameters
rows:int

The number of rows in the map

size:int

The number of entries in the map

shift:int

The value by which hash codes are right-shifted

mask:int

The value with which hash codes are masked after being shifted

Method Detail

entrySetback to summary
public Set<Map.Entry<String, V>> entrySet()

Implements abstract java.util.AbstractMap.entrySet.

Implements java.util.Map.entrySet.

Doc from java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation, or through the setValue operation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

getback to summary
public V get(Object k)

Overrides java.util.AbstractMap.get.

Implements java.util.Map.get.

Doc from java.util.AbstractMap.get.

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

More formally, if this map contains a mapping from a key k to a value v such that Objects.equals(key, k), then this method returns v; otherwise it returns null. (There can be at most one such mapping.)

If this map permits null values, then a return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.

initback to summary
protected abstract void init(Object[] ht)

Initializes this map.

This method must construct the map's hash chains and store them into the appropriate elements of the given hash-table row array.

Parameters
ht:Object[]

The row array to be initialized

keySetback to summary
public Set<String> keySet()

Overrides java.util.AbstractMap.keySet.

Implements java.util.Map.keySet.

Doc from java.util.AbstractMap.keySet.

Returns a Set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.

putback to summary
public V put(String k, V v)

Overrides java.util.AbstractMap.put.

Implements java.util.Map.put.

Doc from java.util.AbstractMap.put.

Associates the specified value with the specified key in this map (optional operation). If the map previously contained a mapping for the key, the old value is replaced by the specified value. (A map m is said to contain a mapping for a key k if and only if m.containsKey(k) would return true.)

Exceptions
UnsupportedOperationException:
If the given key is not part of this map's initial key set
toVback to summary
private V toV(Object x)
Annotations
@SuppressWarnings:unchecked