Class IntIntMap

java.lang.Object
cloud.opencode.base.collections.primitive.IntIntMap
All Implemented Interfaces:
Serializable

public final class IntIntMap extends Object implements Serializable
IntIntMap - Primitive int-to-int Map Implementation IntIntMap - 原始 int 到 int 映射实现

A map specialized for primitive int keys and values to avoid boxing overhead.

专门用于原始 int 键和值的映射,以避免装箱开销。

Features | 主要功能:

  • No boxing overhead - 无装箱开销
  • Memory efficient - 内存高效
  • Fast operations - 快速操作

Usage Examples | 使用示例:

IntIntMap map = IntIntMap.create();
map.put(1, 100);
map.put(2, 200);

int value = map.get(1);       // 100
int def = map.getOrDefault(3, -1); // -1

Performance | 性能特性:

  • put: O(1) average - put: O(1) 平均
  • get: O(1) average - get: O(1) 平均
  • remove: O(1) average - remove: O(1) 平均

Security | 安全性:

  • Thread-safe: No - 否
  • Null-safe: No (primitive values, no null) - 否(原始值,无null)
Since:
JDK 25, opencode-base-collections V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • create

      public static IntIntMap create()
      Create an empty IntIntMap. 创建空 IntIntMap。
      Returns:
      new empty IntIntMap | 新空 IntIntMap
    • create

      public static IntIntMap create(int initialCapacity)
      Create an IntIntMap with initial capacity. 创建指定初始容量的 IntIntMap。
      Parameters:
      initialCapacity - initial capacity | 初始容量
      Returns:
      new empty IntIntMap | 新空 IntIntMap
    • put

      public int put(int key, int value)
      Put a key-value pair. 放入键值对。
      Parameters:
      key - the key | 键
      value - the value | 值
      Returns:
      the old value or NO_VALUE | 旧值或 NO_VALUE
    • get

      public int get(int key)
      Get the value for a key. 获取键对应的值。
      Parameters:
      key - the key | 键
      Returns:
      the value | 值
      Throws:
      NoSuchElementException - if key not found | 如果键未找到
    • getOrDefault

      public int getOrDefault(int key, int defaultValue)
      Get the value for a key or default. 获取键对应的值或默认值。
      Parameters:
      key - the key | 键
      defaultValue - the default value | 默认值
      Returns:
      the value or default | 值或默认值
    • remove

      public int remove(int key)
      Remove a key-value pair. 移除键值对。
      Parameters:
      key - the key | 键
      Returns:
      the old value or NO_VALUE | 旧值或 NO_VALUE
    • containsKey

      public boolean containsKey(int key)
      Check if this map contains the key. 检查此映射是否包含该键。
      Parameters:
      key - the key | 键
      Returns:
      true if contains | 如果包含则返回 true
    • containsValue

      public boolean containsValue(int value)
      Check if this map contains the value. 检查此映射是否包含该值。
      Parameters:
      value - the value | 值
      Returns:
      true if contains | 如果包含则返回 true
    • size

      public int size()
      Return the size of this map. 返回此映射的大小。
      Returns:
      the size | 大小
    • isEmpty

      public boolean isEmpty()
      Check if this map is empty. 检查此映射是否为空。
      Returns:
      true if empty | 如果为空则返回 true
    • clear

      public void clear()
      Clear this map. 清空此映射。
    • keySet

      public IntSet keySet()
      Return all keys as an IntSet. 以 IntSet 形式返回所有键。
      Returns:
      the keys | 键
    • valuesToArray

      public int[] valuesToArray()
      Return all values as an array. 以数组形式返回所有值。
      Returns:
      the values | 值
    • forEach

      public void forEach(IntIntMap.IntIntConsumer action)
      Apply action to each entry. 对每个条目应用操作。
      Parameters:
      action - the action | 操作
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object