Class LongSet

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

public final class LongSet extends Object implements Serializable
LongSet - Primitive long Set Implementation LongSet - 原始 long 集合实现

A set specialized for primitive long values to avoid boxing overhead.

专门用于原始 long 值的集合,以避免装箱开销。

Features | 主要功能:

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

Usage Examples | 使用示例:

LongSet set = LongSet.create();
set.add(1L);
set.add(2L);
set.add(3L);

boolean contains = set.contains(2L);  // true
long[] array = set.toLongArray();     // [1, 2, 3]

Performance | 性能特性:

  • add: O(1) average - add: O(1) 平均
  • remove: O(1) average - remove: O(1) 平均
  • contains: O(1) average - contains: 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 LongSet create()
      Create an empty LongSet. 创建空 LongSet。
      Returns:
      new empty LongSet | 新空 LongSet
    • create

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

      public static LongSet of(long... values)
      Create a LongSet from values. 从值创建 LongSet。
      Parameters:
      values - the values | 值
      Returns:
      new LongSet | 新 LongSet
    • add

      public boolean add(long value)
      Add a value to this set. 向此集合添加值。
      Parameters:
      value - the value | 值
      Returns:
      true if added | 如果添加则返回 true
    • remove

      public boolean remove(long value)
      Remove a value from this set. 从此集合移除值。
      Parameters:
      value - the value | 值
      Returns:
      true if removed | 如果移除则返回 true
    • contains

      public boolean contains(long value)
      Check if this set contains the value. 检查此集合是否包含该值。
      Parameters:
      value - the value | 值
      Returns:
      true if contains | 如果包含则返回 true
    • size

      public int size()
      Return the size of this set. 返回此集合的大小。
      Returns:
      the size | 大小
    • isEmpty

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

      public void clear()
      Clear this set. 清空此集合。
    • toLongArray

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

      public void forEach(LongSet.LongConsumer action)
      Apply action to each value. 对每个值应用操作。
      Parameters:
      action - the action | 操作
    • iterator

      public PrimitiveIterator.OfLong iterator()
      Return an iterator over the values. 返回值的迭代器。
      Returns:
      the iterator | 迭代器
    • 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