Top Description Inners Fields Constructors Methods
com.carrotsearch.hppc

public Class IntObjectHashMap<VType>

extends Object
implements IntObjectMap<VType>, Preallocable, Cloneable, Accountable
Class Inheritance
All Implemented Interfaces
com.carrotsearch.hppc.Accountable, java.lang.Cloneable, com.carrotsearch.hppc.Preallocable, com.carrotsearch.hppc.IntObjectMap, com.carrotsearch.hppc.IntObjectAssociativeContainer, java.lang.Iterable
Annotations
@SuppressWarnings:unchecked
@Generated:KTypeVTypeHashMap.java
date:2024-06-04T15:20:16+0200
Static Imports
com.carrotsearch.hppc.Containers.*, com.carrotsearch.hppc.HashContainers.*

A hash map of int to Object, implemented using open addressing with linear probing for collision resolution. Supports null values.
See Also
HPPC interfaces diagram

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
IntObjectHashMap.EntryIterator

An iterator implementation for iterator.

public class
IntObjectHashMap.KeysContainer

A view of the keys inside this hash map.

private class
IntObjectHashMap.KeysIterator

An iterator over the set of assigned keys.

private class
IntObjectHashMap.ValuesContainer

A view over the set of values of this map.

private class
IntObjectHashMap.ValuesIterator

An iterator over the set of assigned values.

Field Summary

Modifier and TypeField and Description
protected int
assigned

The number of stored keys (assigned key slots), excluding the special "empty" key, if any (use size() instead).

protected boolean
hasEmptyKey

Special treatment for the "empty slot" key marker.

protected int
iterationSeed

Seed used to ensure the hash iteration order is different from an iteration to another.

public int[]
keys

The array holding keys.

protected double
loadFactor

The load factor for keys.

protected int
mask

Mask for slot scans in keys.

protected int
resizeAt

Expand (rehash) keys when assigned hits this value.

public Object[]
values

The array holding values.

Constructor Summary

AccessConstructor and Description
public
IntObjectHashMap()

New instance with sane defaults.

public
IntObjectHashMap(int
The expected number of elements guaranteed not to cause buffer expansion (inclusive).
expectedElements
)

New instance with sane defaults.

public
IntObjectHashMap(int
The expected number of elements guaranteed not to cause a rehash (inclusive).
expectedElements
,
double
The load factor for internal buffers. Insane load factors (zero, full capacity) are rejected by verifyLoadFactor(double).
loadFactor
)

New instance with the provided defaults.

public
IntObjectHashMap(IntObjectAssociativeContainer<? extends VType> container)

Create a hash map from all key-value pairs of another container.

Method Summary

Modifier and TypeMethod and Description
protected void
allocateBuffers(int arraySize)

Allocate new internal buffers.

protected void
allocateThenInsertThenRehash(int slot, int pendingKey, VType pendingValue)

This method is invoked when there is a new key/ value pair to be inserted into the buffers but there is not enough empty slots to do so.

public void
clear()

Implements com.carrotsearch.hppc.IntObjectMap.clear.

Clear all keys and values in the container.

public IntObjectHashMap<VType>
clone()

Overrides java.lang.Object.clone.

Creates and returns a copy of this object.

public boolean
containsKey(int key)

Implements com.carrotsearch.hppc.IntObjectAssociativeContainer.containsKey.

Returns true if this container has an association to a value for the given key.

public void
ensureCapacity(int
The total number of keys, inclusive.
expectedElements
)

Implements com.carrotsearch.hppc.Preallocable.ensureCapacity.

Ensure this container can hold at least the given number of keys (entries) without resizing its buffers.

protected boolean
equalElements(IntObjectHashMap<?> other)

Return true if all keys of some other container exist in this container.

public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Implements com.carrotsearch.hppc.IntObjectMap.equals.

Compares the specified object with this set for equality.

public <T extends IntObjectProcedure<? super VType>> T
forEach(T procedure)

Implements com.carrotsearch.hppc.IntObjectAssociativeContainer.forEach, com.carrotsearch.hppc.IntObjectAssociativeContainer.forEach.

Applies a given procedure to all keys-value pairs in this container.

public <T extends IntObjectPredicate<? super VType>> T
forEach(T predicate)

Implements com.carrotsearch.hppc.IntObjectAssociativeContainer.forEach, com.carrotsearch.hppc.IntObjectAssociativeContainer.forEach.

Applies a given procedure to all keys-value pairs in this container.

public static <VType> IntObjectHashMap<VType>
from(int[] keys, VType[] values)

Creates a hash map from two index-aligned arrays of key-value pairs.

public VType
public VType
getOrDefault(int key, VType defaultValue)

Implements com.carrotsearch.hppc.IntObjectMap.getOrDefault.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Implements com.carrotsearch.hppc.IntObjectMap.hashCode.

Returns a hash code value for this object.

protected int
hashKey(int key)

Returns a hash code for the given key.

public boolean
indexExists(int
The index of a given key, as returned from indexOf.
index
)

Implements com.carrotsearch.hppc.IntObjectMap.indexExists.

public VType
indexGet(int
The index of an existing key.
index
)

Implements com.carrotsearch.hppc.IntObjectMap.indexGet.

Returns the value associated with an existing key.

public void
indexInsert(int
The index of a previously non-existing key, as returned from indexOf.
index
,
int key, VType value)

Implements com.carrotsearch.hppc.IntObjectMap.indexInsert.

Inserts a key-value pair for a key that is not present in the map.

public int
indexOf(int
The key to locate in the map.
key
)

Implements com.carrotsearch.hppc.IntObjectMap.indexOf.

Returns a logical "index" of a given key that can be used to speed up follow-up value setters or getters in certain scenarios (conditional logic).

public VType
indexRemove(int
The index of the key to remove, as returned from indexOf.
index
)

Implements com.carrotsearch.hppc.IntObjectMap.indexRemove.

Removes a key-value pair at an index previously acquired from indexOf.

public VType
indexReplace(int
The index of an existing key.
index
,
VType newValue)

Implements com.carrotsearch.hppc.IntObjectMap.indexReplace.

Replaces the value associated with an existing key and returns any previous value stored for that key.

public boolean
public Iterator<IntObjectCursor<VType>>
iterator()

Implements com.carrotsearch.hppc.IntObjectAssociativeContainer.iterator.

Returns a cursor over the entries (key-value pairs) in this map.

public IntObjectHashMap<VType>.KeysContainer
keys()

Implements com.carrotsearch.hppc.IntObjectAssociativeContainer.keys.

Returns a specialized view of the keys of this associated container.

protected int
nextIterationSeed()

Provides the next iteration seed used to build the iteration starting slot and offset increment.

public VType
put(int key, VType value)

Implements com.carrotsearch.hppc.IntObjectMap.put.

Place a given key and value in the container.

public int
putAll(IntObjectAssociativeContainer<? extends VType> container)

Implements com.carrotsearch.hppc.IntObjectMap.putAll.

Puts all keys from another container to this map, replacing the values of existing keys, if such keys are present.

public int
putAll(Iterable<? extends IntObjectCursor<? extends VType>> iterable)

Implements com.carrotsearch.hppc.IntObjectMap.putAll.

Puts all key/value pairs from a given iterable into this map.

public long
public long
ramBytesUsed()

Implements com.carrotsearch.hppc.Accountable.ramBytesUsed.

Bytes that is actually been used

protected void
rehash(int[] fromKeys, VType[] fromValues)

Rehash from old buffers to new buffers.

public void
release()

Implements com.carrotsearch.hppc.IntObjectMap.release.

Removes all elements from the collection and additionally releases any internal buffers.

public VType
remove(int key)

Implements com.carrotsearch.hppc.IntObjectMap.remove.

Remove all values at the given key.

public int
removeAll(IntContainer other)

Implements com.carrotsearch.hppc.IntObjectAssociativeContainer.removeAll.

Removes all keys (and associated values) present in a given container.

public int
removeAll(IntObjectPredicate<? super VType> predicate)

Implements com.carrotsearch.hppc.IntObjectAssociativeContainer.removeAll.

Removes all keys (and associated values) for which the predicate returns true.

public int
removeAll(IntPredicate predicate)

Implements com.carrotsearch.hppc.IntObjectAssociativeContainer.removeAll.

Removes all keys (and associated values) for which the predicate returns true.

protected void
shiftConflictingKeys(int gapSlot)

Shift all the slot-conflicting keys and values allocated to (and including) slot.

public int
public String
toString()

Overrides java.lang.Object.toString.

Convert the contents of this map to a human-friendly string.

public ObjectCollection<VType>

Returns:

Returns a container with all values stored in this map.
values
()

Implements com.carrotsearch.hppc.IntObjectAssociativeContainer.values.

Returns a container view of all values present in this container.

protected double
verifyLoadFactor(double loadFactor)

Validate load factor range and return it.

public String
visualizeKeyDistribution(int
The number of characters to "squeeze" the entire buffer into.
characters
)

Implements com.carrotsearch.hppc.IntObjectMap.visualizeKeyDistribution.

Visually depict the distribution of keys.

Inherited from java.lang.Object:
finalizegetClassnotifynotifyAllwaitwaitwait