Top Description Inners Fields Constructors Methods
org.jboss.logmanager

pack-priv Class FastCopyHashMap<K, V>

extends AbstractMap<K, V>
implements Map<K, V>, Cloneable, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.Cloneable, java.util.Map
Imports
java.io.IOException, .Serializable, java.util.AbstractCollection, .AbstractMap, .AbstractSet, .Collection, .ConcurrentModificationException, .Iterator, .Map, .NoSuchElementException, .Set

A HashMap that is optimized for fast shallow copies. If the copy-ctor is passed another FastCopyHashMap, or clone is called on this map, the shallow copy can be performed using little more than a single array copy. In order to accomplish this, immutable objects must be used internally, so update operations result in slightly more object churn than HashMap.

Note

It is very important to use a smaller load factor than you normally would for HashMap, since the implementation is open-addressed with linear probing. With a 50% load-factor a get is expected to return in only 2 probes. However, a 90% load-factor is expected to return in around 50 probes.

Author
Jason T. Greene

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private class
private class
private abstract class
private class
private class
protected static class
private class
private class

Field Summary

Modifier and TypeField and Description
private static final int
DEFAULT_CAPACITY

Same default as HashMap, must be a power of 2

private static final float
DEFAULT_LOAD_FACTOR

67%, just like IdentityHashMap

private transient FastCopyHashMap<K, V>.EntrySet
private transient FastCopyHashMap<K, V>.KeySet
private final float
loadFactor

The user defined load factor which defines when to resize

private static final int
MAXIMUM_CAPACITY

MAX_INT - 1

private transient int
modCount

Counter used to detect changes made outside of an iterator

private static final Object
NULL

Marks null keys.

private static final long
serialVersionUID

Serialization ID

private transient int
size

The current number of key-value pairs

private transient FastCopyHashMap.Entry<K, V>[]
table

The open-addressed table

private transient int
threshold

The next resize

private transient FastCopyHashMap<K, V>.Values

Constructor Summary

AccessConstructor and Description
public
FastCopyHashMap(int initialCapacity, float loadFactor)

public
FastCopyHashMap(Map<? extends K, ? extends V> map)

public
FastCopyHashMap(int initialCapacity)

public

Method Summary

Modifier and TypeMethod and Description
public void
clear()

Overrides java.util.AbstractMap.clear.

Implements java.util.Map.clear.

Removes all of the mappings from this map (optional operation).

public FastCopyHashMap<K, V>
clone()

Overrides java.util.AbstractMap.clone.

Returns a shallow copy of this AbstractMap instance: the keys and values themselves are not cloned.

public boolean
containsKey(Object
key whose presence in this map is to be tested
key
)

Overrides java.util.AbstractMap.containsKey.

Implements java.util.Map.containsKey.

Returns true if this map contains a mapping for the specified key.

public boolean
containsValue(Object
value whose presence in this map is to be tested
value
)

Overrides java.util.AbstractMap.containsValue.

Implements java.util.Map.containsValue.

Returns true if this map maps one or more keys to the specified value.

public Set<Map.Entry<K, V>>
entrySet()

Implements abstract java.util.AbstractMap.entrySet.

Implements java.util.Map.entrySet.

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

private static final boolean
eq(Object o1, Object o2)

Hides java.util.AbstractMap.eq.

Utility method for SimpleEntry and SimpleImmutableEntry.

public V
get(Object
the key whose associated value is to be returned
key
)

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.

private static final int
hash(Object key)

private static final int
index(int hashCode, int length)

private void
init(int initialCapacity, float loadFactor)

public boolean
isEmpty()

Overrides java.util.AbstractMap.isEmpty.

Implements java.util.Map.isEmpty.

Returns true if this map contains no key-value mappings.

public Set<K>
keySet()

Overrides java.util.AbstractMap.keySet.

Implements java.util.Map.keySet.

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

private static final <K> K
maskNull(K key)

private int
nextIndex(int index, int length)

public static <K, V> FastCopyHashMap<K, V>
of(Map<K, V> map)

public void
public V
put(K
key with which the specified value is to be associated
key
,
V
value to be associated with the specified key
value
)

Overrides java.util.AbstractMap.put.

Implements java.util.Map.put.

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

public void
putAll(Map<? extends K, ? extends V>
mappings to be stored in this map
map
)

Overrides java.util.AbstractMap.putAll.

Implements java.util.Map.putAll.

Copies all of the mappings from the specified map to this map (optional operation).

private void
putForCreate(K key, V value)

private void
private void
relocate(int start)

public V
remove(Object
key whose mapping is to be removed from the map
key
)

Overrides java.util.AbstractMap.remove.

Implements java.util.Map.remove.

Removes the mapping for a key from this map if it is present (optional operation).

private void
resize(int from)

public int
size()

Overrides java.util.AbstractMap.size.

Implements java.util.Map.size.

Returns the number of key-value mappings in this map.

private static final <K> K
unmaskNull(K key)

public Collection<V>
values()

Overrides java.util.AbstractMap.values.

Implements java.util.Map.values.

Returns a Collection view of the values contained in this map.

private void
Inherited from java.util.AbstractMap:
equalshashCodetoString