HashMap

class HashMap : AbstractMap!(K, V)(
K
V
) {}

Constructors

this
this(int initialCapacity, float loadFactor)

Constructs an empty <tt>HashMap</tt> with the specified initial capacity and load factor.

this
this(int initialCapacity)

Constructs an empty <tt>HashMap</tt> with the specified initial capacity and the default load factor (0.75).

this
this()

Constructs an empty <tt>HashMap</tt> with the default initial capacity (16) and the default load factor (0.75).

this
this(Map!(K, V) m)

Constructs a new <tt>HashMap</tt> with the same mappings as the specified <tt>Map</tt>. The <tt>HashMap</tt> is created with default load factor (0.75) and an initial capacity sufficient to hold the mappings in the specified <tt>Map</tt>.

Members

Aliases

remove
alias remove = AbstractMap!(K, V).remove
Undocumented in source.

Classes

KeyInputRange
class KeyInputRange
Undocumented in source.
ValueInputRange
class ValueInputRange
Undocumented in source.

Functions

afterNodeAccess
void afterNodeAccess(HashMapNode!(K, V) p)
Undocumented in source. Be warned that the author may not have intended to support it.
afterNodeInsertion
void afterNodeInsertion(bool evict)
Undocumented in source. Be warned that the author may not have intended to support it.
afterNodeRemoval
void afterNodeRemoval(HashMapNode!(K, V) p)
Undocumented in source. Be warned that the author may not have intended to support it.
byKey
InputRange!K byKey()
Undocumented in source. Be warned that the author may not have intended to support it.
byValue
InputRange!V byValue()
Undocumented in source. Be warned that the author may not have intended to support it.
clear
void clear()

Removes all of the mappings from this map. The map will be empty after this call returns.

containsKey
bool containsKey(K key)

Returns <tt>true</tt> if this map contains a mapping for the specified key.

containsValue
bool containsValue(V value)

Returns <tt>true</tt> if this map maps one or more keys to the specified value.

get
V get(K key)

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

getNode
HashMapNode!(K, V) getNode(size_t hash, K key)

Implements Map.get and related methods

newNode
HashMapNode!(K, V) newNode(size_t hash, K key, V value, HashMapNode!(K, V) next)
Undocumented in source. Be warned that the author may not have intended to support it.
newTreeNode
TreeNode!(K, V) newTreeNode(size_t hash, K key, V value, HashMapNode!(K, V) next)
Undocumented in source. Be warned that the author may not have intended to support it.
opApply
int opApply(int delegate(ref K, ref V) dg)

Returns a {@link 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 <tt>remove</tt> operation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the <tt>Iterator.remove</tt>, <tt>Set.remove</tt>, <tt>removeAll</tt>, <tt>retainAll</tt>, and <tt>clear</tt> operations. It does not support the <tt>add</tt> or <tt>addAll</tt> operations.

opApply
int opApply(int delegate(MapEntry!(K, V) entry) dg)
Undocumented in source. Be warned that the author may not have intended to support it.
put
V put(K key, V value)

Associates the specified value with the specified key in this map. If the map previously contained a mapping for the key, the old value is replaced.

putMapEntries
void putMapEntries(Map!(K, V) m, bool evict)

Implements Map.putAll and Map constructor

putVal
V putVal(size_t hash, K key, V value, bool onlyIfAbsent, bool evict)

Implements Map.put and related methods

reinitialize
void reinitialize()

Reset to initial default state. Called by clone and readObject.

remove
V remove(K key)

Removes the mapping for the specified key from this map if present.

removeNode
HashMapNode!(K, V) removeNode(size_t hash, K key, V value, bool matchValue, bool movable)

Implements Map.remove and related methods

replacementNode
HashMapNode!(K, V) replacementNode(HashMapNode!(K, V) p, HashMapNode!(K, V) next)
Undocumented in source. Be warned that the author may not have intended to support it.
replacementTreeNode
TreeNode!(K, V) replacementTreeNode(HashMapNode!(K, V) p, HashMapNode!(K, V) next)
Undocumented in source. Be warned that the author may not have intended to support it.
resize
HashMapNode!(K, V)[] resize()

Initializes or doubles table size. If null, allocates in accord with initial capacity target held in field threshold. Otherwise, because we are using power-of-two expansion, the elements from each bin must either stay at same index, or move with a power of two offset in the new table.

treeifyBin
void treeifyBin(HashMapNode!(K, V)[] tab, size_t hash)

Replaces all linked nodes in bin at index for given hash unless table is too small, in which case resizes instead.

Mixin templates

HashIterator
mixintemplate HashIterator()
Undocumented in source.

Static functions

hash
size_t hash(K key)

Computes key.toHash() and spreads (XORs) higher bits of hash to lower. Because the table uses power-of-two masking, sets of hashes that vary only in bits above the current mask will always collide. (Among known examples are sets of Float keys holding consecutive whole numbers in small tables.) So we apply a transform that spreads the impact of higher bits downward. There is a tradeoff between speed, utility, and quality of bit-spreading. Because many common sets of hashes are already reasonably distributed (so don't benefit from spreading), and because we use trees to handle large sets of collisions in bins, we just XOR some shifted bits in the cheapest possible way to reduce systematic lossage, as well as to incorporate impact of the highest bits that would otherwise never be used in index calculations because of table bounds.

tableSizeFor
int tableSizeFor(int cap)

Returns a power of two size for the given target capacity.

Variables

DEFAULT_INITIAL_CAPACITY
enum int DEFAULT_INITIAL_CAPACITY;

The default initial capacity - MUST be a power of two.

DEFAULT_LOAD_FACTOR
enum float DEFAULT_LOAD_FACTOR;

The load factor used when none specified in constructor.

MAXIMUM_CAPACITY
enum int MAXIMUM_CAPACITY;

The maximum capacity, used if a higher value is implicitly specified by either of the constructors with arguments. MUST be a power of two <= 1<<30.

MIN_TREEIFY_CAPACITY
enum int MIN_TREEIFY_CAPACITY;

The smallest table capacity for which bins may be treeified. (Otherwise the table is resized if too many nodes in a bin.) Should be at least 4 * TREEIFY_THRESHOLD to avoid conflicts between resizing and treeification thresholds.

TREEIFY_THRESHOLD
enum int TREEIFY_THRESHOLD;

The bin count threshold for using a tree rather than list for a bin. Bins are converted to trees when adding an element to a bin with at least this many nodes. The value must be greater than 2 and should be at least 8 to mesh with assumptions in tree removal about conversion back to plain bins upon shrinkage.

loadFactor
float loadFactor;

The load factor for the hash table.

modCount
int modCount;

The number of times this HashMap has been structurally modified Structural modifications are those that change the number of mappings in the HashMap or otherwise modify its internal structure (e.g., rehash). This field is used to make iterators on Collection-views of the HashMap fail-fast. (See ConcurrentModificationException).

table
HashMapNode!(K, V)[] table;

The table, initialized on first use, and resized as necessary. When allocated, length is always a power of two. (We also tolerate length zero in some operations to allow bootstrapping mechanics that are currently not needed.)

threshold
int threshold;

The next size value at which to resize (capacity * load factor).

Meta