- All Superinterfaces:
Iterable<ShortShortCursor>
,ShortShortAssociativeContainer
- All Known Implementing Classes:
ShortShortHashMap
,SortedIterationShortShortHashMap
@Generated(date="2024-06-04T15:20:17+0200",
value="KTypeVTypeMap.java")
public interface ShortShortMap
extends ShortShortAssociativeContainer
An associative container with unique binding from keys to a single value.
-
Method Summary
Modifier and TypeMethodDescriptionshort
addTo
(short key, short additionValue) An equivalent of callingvoid
clear()
Clear all keys and values in the container.boolean
Compares the specified object with this set for equality.short
get
(short key) short
getOrDefault
(short key, short defaultValue) int
hashCode()
boolean
indexExists
(int index) short
indexGet
(int index) Returns the value associated with an existing key.void
indexInsert
(int index, short key, short value) Inserts a key-value pair for a key that is not present in the map.int
indexOf
(short key) 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).short
indexRemove
(int index) Removes a key-value pair at an index previously acquired fromindexOf(short)
.short
indexReplace
(int index, short newValue) Replaces the value associated with an existing key and returns any previous value stored for that key.short
put
(short key, short value) Place a given key and value in the container.int
putAll
(ShortShortAssociativeContainer container) Puts all keys from another container to this map, replacing the values of existing keys, if such keys are present.int
putAll
(Iterable<? extends ShortShortCursor> iterable) Puts all keys from an iterable cursor to this map, replacing the values of existing keys, if such keys are present.default boolean
putIfAbsent
(short key, short value) If the specified key is not already associated with a value, associates it with the given value.short
putOrAdd
(short key, short putValue, short incrementValue) Ifkey
exists,putValue
is inserted into the map, otherwise any existing value is incremented byadditionValue
.void
release()
Removes all elements from the collection and additionally releases any internal buffers.short
remove
(short key) Remove all values at the given key.visualizeKeyDistribution
(int characters) Visually depict the distribution of keys.Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
get
short get(short key) - Returns:
- Returns the value associated with the given key or the default value for the value
type, if the key is not associated with any value. For numeric value types, this default
value is 0, for object types it is
null
.
-
getOrDefault
short getOrDefault(short key, short defaultValue) - Returns:
- Returns the value associated with the given key or the provided default value if the key is not associated with any value.
-
put
short put(short key, short value) Place a given key and value in the container.- Returns:
- The value previously stored under the given key in the map is returned.
-
putIfAbsent
default boolean putIfAbsent(short key, short value) If the specified key is not already associated with a value, associates it with the given value.- Returns:
true
ifkey
did not exist andvalue
was placed in the map,false
otherwise.
-
putAll
Puts all keys from another container to this map, replacing the values of existing keys, if such keys are present.- Returns:
- Returns the number of keys added to the map as a result of this call (not previously present in the map). Values of existing keys are overwritten.
-
putAll
Puts all keys from an iterable cursor to this map, replacing the values of existing keys, if such keys are present.- Returns:
- Returns the number of keys added to the map as a result of this call (not previously present in the map). Values of existing keys are overwritten.
-
putOrAdd
short putOrAdd(short key, short putValue, short incrementValue) Ifkey
exists,putValue
is inserted into the map, otherwise any existing value is incremented byadditionValue
.- Parameters:
key
- The key of the value to adjust.putValue
- The value to put ifkey
does not exist.incrementValue
- The value to add to the existing value ifkey
exists.- Returns:
- Returns the current value associated with
key
(after changes).
-
addTo
short addTo(short key, short additionValue) An equivalent of callingputOrAdd(key, additionValue, additionValue);
- Parameters:
key
- The key of the value to adjust.additionValue
- The value to put or add to the existing value ifkey
exists.- Returns:
- Returns the current value associated with
key
(after changes).
-
remove
short remove(short key) Remove all values at the given key. The default value for the key type is returned if the value does not exist in the map. -
equals
Compares the specified object with this set for equality. Returnstrue
if and only if the specified object is also aShortShortMap
and both objects contains exactly the same key-value pairs. -
hashCode
int hashCode() -
indexOf
int indexOf(short key) 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).The semantics of "indexes" are not strictly defined. Indexes may (and typically won't be) contiguous.
The index is valid only between map modifications (it will not be affected by read-only operations like iteration or value retrievals).
- Parameters:
key
- The key to locate in the map.- Returns:
- A non-negative value of the logical "index" of the key in the map or a negative value if the key did not exist.
- See Also:
-
indexExists
boolean indexExists(int index) - Parameters:
index
- The index of a given key, as returned fromindexOf(short)
.- Returns:
- Returns
true
if the index corresponds to an existing key or false otherwise. This is equivalent to checking whether the index is a positive value (existing keys) or a negative value (non-existing keys). - See Also:
-
indexGet
short indexGet(int index) Returns the value associated with an existing key.- Parameters:
index
- The index of an existing key.- Returns:
- Returns the value currently associated with the key.
- Throws:
AssertionError
- If assertions are enabled and the index does not correspond to an existing key.- See Also:
-
indexReplace
short indexReplace(int index, short newValue) Replaces the value associated with an existing key and returns any previous value stored for that key.- Parameters:
index
- The index of an existing key.- Returns:
- Returns the previous value associated with the key.
- Throws:
AssertionError
- If assertions are enabled and the index does not correspond to an existing key.- See Also:
-
indexInsert
void indexInsert(int index, short key, short value) Inserts a key-value pair for a key that is not present in the map. This method may help in avoiding double recalculation of the key's hash.- Parameters:
index
- The index of a previously non-existing key, as returned fromindexOf(short)
.- Throws:
AssertionError
- If assertions are enabled and the index corresponds to an existing key.- See Also:
-
indexRemove
short indexRemove(int index) Removes a key-value pair at an index previously acquired fromindexOf(short)
.- Parameters:
index
- The index of the key to remove, as returned fromindexOf(short)
.- Returns:
- Returns the previous value associated with the key.
- Throws:
AssertionError
- If assertions are enabled and the index does not correspond to an existing key.- See Also:
-
clear
void clear()Clear all keys and values in the container.- See Also:
-
release
void release()Removes all elements from the collection and additionally releases any internal buffers. Typically, if the object is to be reused, a simpleclear()
should be a better alternative since it'll avoid reallocation.- See Also:
-
visualizeKeyDistribution
Visually depict the distribution of keys.- Parameters:
characters
- The number of characters to "squeeze" the entire buffer into.- Returns:
- Returns a sequence of characters where '.' depicts an empty fragment of the internal buffer and 'X' depicts full or nearly full capacity within the buffer's range and anything between 1 and 9 is between.
-