Class Int2IntMap
-
- All Implemented Interfaces:
public final class Int2IntMapSimple map for Int to Int relations. Designed for small to medium maps with a low amount of entries (<1000).
As there is no way to specify invalid values, a return value of
0is given when the mapping does not exist. While it does mostly comply to the MutableMap interface, it is not implemented for performance reasons and for simplicity. It is designed to be used as a drop in replacement for a Map when the key is an Int and the value is an Int.Implemented as a dual sorted array with binary search for fast lookups. Here is a summary of the performance characteristics:
Best/Average Case: 𝑂(log 𝑛). Searching is performed using a binary algorithm.
Best/Average Case: 𝑂(log 𝑛) for the binary search and 𝑂(1) for the insertion without resizing.
Worst Case: 𝑂(log 𝑛) for the binary search and 𝑂(𝑛) for the insertion with array shifting and resizing.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final classInt2IntMap.Iterpublic final classInt2IntMap.Entry
-
Constructor Summary
Constructors Constructor Description Int2IntMap(Integer initialCapacity)
-
Method Summary
Modifier and Type Method Description final IntegergetSize()final BooleanisEmpty()final Integerget(IntegerĀ key)Get the value associated with the given key. final Unitset(IntegerĀ key, IntegerĀ value)final Unitput(IntegerĀ key, IntegerĀ value)final Booleancontains(IntegerĀ key)final BooleancontainsKey(IntegerĀ key)final BooleancontainsValue(IntegerĀ value)final Integerremove(IntegerĀ key)Remove the mapping for the given key. final Unittrim()Trim the internal arrays to the current size. final Unitclear()Clear the map. final IntegergetOrPut(IntegerĀ key, Function0<Integer>Ā defaultValue)final UnitforEach(Function2<Integer, Integer, Unit>Ā action)final Int2IntMap.Iteriterator()-
-
Constructor Detail
-
Int2IntMap
Int2IntMap(Integer initialCapacity)
-
-
Method Detail
-
get
final Integer get(IntegerĀ key)
Get the value associated with the given key.
- Returns:
the value associated with the key, or
0if the key was not present.
-
containsKey
final Boolean containsKey(IntegerĀ key)
-
containsValue
final Boolean containsValue(IntegerĀ value)
-
remove
final Integer remove(IntegerĀ key)
Remove the mapping for the given key.
- Returns:
the previous value associated with the key, or
0if the key was not present.
-
trim
final Unit trim()
Trim the internal arrays to the current size. This is useful when the map will not be modified anymore.
Requires a full copy of the arrays, so it is not recommended to be used frequently. It also means next insertion will require another copy.
-
clear
final Unit clear()
Clear the map. This does not actually discard any data for performance reasons.
-
iterator
final Int2IntMap.Iter iterator()
-
-
-
-