Top Description Inners Fields Constructors Methods
com.carrotsearch.hppc

public Class CharByteHashMap

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

A hash map of char to byte, implemented using open addressing with linear probing for collision resolution.
See Also
HPPC interfaces diagram

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
CharByteHashMap.EntryIterator

An iterator implementation for iterator.

public class
CharByteHashMap.KeysContainer

A view of the keys inside this hash map.

private class
CharByteHashMap.KeysIterator

An iterator over the set of assigned keys.

private class
CharByteHashMap.ValuesContainer

A view over the set of values of this map.

private class
CharByteHashMap.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 char[]
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 byte[]
values

The array holding values.

Constructor Summary

AccessConstructor and Description
public
CharByteHashMap()

New instance with sane defaults.

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

New instance with sane defaults.

public
CharByteHashMap(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
CharByteHashMap(CharByteAssociativeContainer container)

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

Method Summary

Modifier and TypeMethod and Description
public byte

Returns:

Returns the current value associated with key (after changes).
addTo
(char
The key of the value to adjust.
key
,
byte
The value to put or add to the existing value if key exists.
incrementValue
)

Implements com.carrotsearch.hppc.CharByteMap.addTo.

Adds incrementValue to any existing value for the given key or inserts incrementValue if key did not previously exist.

protected void
allocateBuffers(int arraySize)

Allocate new internal buffers.

protected void
allocateThenInsertThenRehash(int slot, char pendingKey, byte 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.CharByteMap.clear.

Clear all keys and values in the container.

public CharByteHashMap
clone()

Overrides java.lang.Object.clone.

Creates and returns a copy of this object.

public boolean
containsKey(char key)

Implements com.carrotsearch.hppc.CharByteAssociativeContainer.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(CharByteHashMap 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.CharByteMap.equals.

Compares the specified object with this set for equality.

public <T extends CharByteProcedure> T
forEach(T procedure)

Implements com.carrotsearch.hppc.CharByteAssociativeContainer.forEach, com.carrotsearch.hppc.CharByteAssociativeContainer.forEach.

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

public <T extends CharBytePredicate> T
forEach(T predicate)

Implements com.carrotsearch.hppc.CharByteAssociativeContainer.forEach, com.carrotsearch.hppc.CharByteAssociativeContainer.forEach.

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

public static CharByteHashMap
from(char[] keys, byte[] values)

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

public byte
public byte
getOrDefault(char key, byte defaultValue)

Implements com.carrotsearch.hppc.CharByteMap.getOrDefault.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Implements com.carrotsearch.hppc.CharByteMap.hashCode.

Returns a hash code value for this object.

protected int
hashKey(char 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.CharByteMap.indexExists.

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

Implements com.carrotsearch.hppc.CharByteMap.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
,
char key, byte value)

Implements com.carrotsearch.hppc.CharByteMap.indexInsert.

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

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

Implements com.carrotsearch.hppc.CharByteMap.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 byte
indexRemove(int
The index of the key to remove, as returned from indexOf.
index
)

Implements com.carrotsearch.hppc.CharByteMap.indexRemove.

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

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

Implements com.carrotsearch.hppc.CharByteMap.indexReplace.

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

public boolean
public Iterator<CharByteCursor>
iterator()

Implements com.carrotsearch.hppc.CharByteAssociativeContainer.iterator.

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

public CharByteHashMap.KeysContainer
keys()

Implements com.carrotsearch.hppc.CharByteAssociativeContainer.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 byte
put(char key, byte value)

Implements com.carrotsearch.hppc.CharByteMap.put.

Place a given key and value in the container.

public int
putAll(CharByteAssociativeContainer container)

Implements com.carrotsearch.hppc.CharByteMap.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 CharByteCursor> iterable)

Implements com.carrotsearch.hppc.CharByteMap.putAll.

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

public byte

Returns:

Returns the current value associated with key (after changes).
putOrAdd
(char
The key of the value to adjust.
key
,
byte
The value to put if key does not exist.
putValue
,
byte
The value to add to the existing value if key exists.
incrementValue
)

Implements com.carrotsearch.hppc.CharByteMap.putOrAdd.

If key exists, putValue is inserted into the map, otherwise any existing value is incremented by additionValue.

public long
public long
ramBytesUsed()

Implements com.carrotsearch.hppc.Accountable.ramBytesUsed.

Bytes that is actually been used

protected void
rehash(char[] fromKeys, byte[] fromValues)

Rehash from old buffers to new buffers.

public void
release()

Implements com.carrotsearch.hppc.CharByteMap.release.

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

public byte
remove(char key)

Implements com.carrotsearch.hppc.CharByteMap.remove.

Remove all values at the given key.

public int
removeAll(CharContainer other)

Implements com.carrotsearch.hppc.CharByteAssociativeContainer.removeAll.

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

public int
removeAll(CharBytePredicate predicate)

Implements com.carrotsearch.hppc.CharByteAssociativeContainer.removeAll.

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

public int
removeAll(CharPredicate predicate)

Implements com.carrotsearch.hppc.CharByteAssociativeContainer.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 ByteCollection

Returns:

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

Implements com.carrotsearch.hppc.CharByteAssociativeContainer.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.CharByteMap.visualizeKeyDistribution.

Visually depict the distribution of keys.

Inherited from java.lang.Object:
finalizegetClassnotifynotifyAllwaitwaitwait