Class TreeRangeMap<K extends Comparable<? super K>, V>

java.lang.Object
cloud.opencode.base.collections.specialized.TreeRangeMap<K,V>
Type Parameters:
K - the type of range endpoints | 范围端点类型
V - the type of values | 值类型
All Implemented Interfaces:
RangeMap<K,V>, Serializable

public final class TreeRangeMap<K extends Comparable<? super K>, V> extends Object implements RangeMap<K,V>, Serializable
TreeRangeMap - Tree-based Range Map Implementation TreeRangeMap - 基于树的范围映射实现

A range map implementation using a tree structure for efficient range operations.

使用树结构进行高效范围操作的范围映射实现。

Features | 主要功能:

  • Automatic range coalescing - 自动范围合并
  • O(log n) operations - O(log n) 操作
  • Efficient range queries - 高效范围查询

Usage Examples | 使用示例:

TreeRangeMap<Integer, String> rangeMap = TreeRangeMap.create();
rangeMap.put(Range.closed(1, 10), "small");
rangeMap.put(Range.closed(11, 100), "medium");

String value = rangeMap.get(5);  // "small"

Performance | 性能特性:

  • get: O(log n) - get: O(log n)
  • put: O(log n + k) where k is removed ranges - put: O(log n + k) 其中 k 是移除的范围数
  • remove: O(log n + k) - remove: O(log n + k)

Security | 安全性:

  • Thread-safe: No - 线程安全: 否
  • Null-safe: Values cannot be null - 空值安全: 值不能为 null
Since:
JDK 25, opencode-base-collections V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • create

      public static <K extends Comparable<? super K>, V> TreeRangeMap<K,V> create()
      Create an empty TreeRangeMap. 创建空 TreeRangeMap。
      Type Parameters:
      K - endpoint type | 端点类型
      V - value type | 值类型
      Returns:
      new empty TreeRangeMap | 新空 TreeRangeMap
    • get

      public V get(K key)
      Description copied from interface: RangeMap
      Get the value associated with the key. 获取与键关联的值。
      Specified by:
      get in interface RangeMap<K extends Comparable<? super K>, V>
      Parameters:
      key - the key | 键
      Returns:
      the value, or null if not found | 值,如果未找到则返回 null
    • getEntry

      public Map.Entry<Range<K>,V> getEntry(K key)
      Description copied from interface: RangeMap
      Get the entry (range and value) containing the key. 获取包含键的条目(范围和值)。
      Specified by:
      getEntry in interface RangeMap<K extends Comparable<? super K>, V>
      Parameters:
      key - the key | 键
      Returns:
      the entry, or null if not found | 条目,如果未找到则返回 null
    • span

      public Range<K> span()
      Description copied from interface: RangeMap
      Return the minimal range that encloses all ranges in this map. 返回包含此映射中所有范围的最小范围。
      Specified by:
      span in interface RangeMap<K extends Comparable<? super K>, V>
      Returns:
      the span | 跨度
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: RangeMap
      Check if this range map is empty. 检查此范围映射是否为空。
      Specified by:
      isEmpty in interface RangeMap<K extends Comparable<? super K>, V>
      Returns:
      true if empty | 如果为空则返回 true
    • asMapOfRanges

      public Map<Range<K>,V> asMapOfRanges()
      Description copied from interface: RangeMap
      Return all range-value mappings as a map. 以映射形式返回所有范围-值映射。
      Specified by:
      asMapOfRanges in interface RangeMap<K extends Comparable<? super K>, V>
      Returns:
      the map | 映射
    • asDescendingMapOfRanges

      public Map<Range<K>,V> asDescendingMapOfRanges()
      Description copied from interface: RangeMap
      Return all range-value mappings in descending order. 以降序返回所有范围-值映射。
      Specified by:
      asDescendingMapOfRanges in interface RangeMap<K extends Comparable<? super K>, V>
      Returns:
      the descending map | 降序映射
    • subRangeMap

      public RangeMap<K,V> subRangeMap(Range<K> range)
      Description copied from interface: RangeMap
      Return a view of the portion of this map within the given range. 返回此映射在给定范围内的部分的视图。
      Specified by:
      subRangeMap in interface RangeMap<K extends Comparable<? super K>, V>
      Parameters:
      range - the range | 范围
      Returns:
      the sub range map | 子范围映射
    • put

      public void put(Range<K> range, V value)
      Description copied from interface: RangeMap
      Associate a range with a value. 将范围与值关联。
      Specified by:
      put in interface RangeMap<K extends Comparable<? super K>, V>
      Parameters:
      range - the range | 范围
      value - the value | 值
    • putCoalescing

      public void putCoalescing(Range<K> range, V value)
      Description copied from interface: RangeMap
      Associate a range with a value, coalescing with adjacent ranges with the same value. 将范围与值关联,与具有相同值的相邻范围合并。
      Specified by:
      putCoalescing in interface RangeMap<K extends Comparable<? super K>, V>
      Parameters:
      range - the range | 范围
      value - the value | 值
    • putAll

      public void putAll(RangeMap<K, ? extends V> rangeMap)
      Description copied from interface: RangeMap
      Put all mappings from another range map. 从另一个范围映射放入所有映射。
      Specified by:
      putAll in interface RangeMap<K extends Comparable<? super K>, V>
      Parameters:
      rangeMap - the other range map | 另一个范围映射
    • remove

      public void remove(Range<K> range)
      Description copied from interface: RangeMap
      Remove a range from this map. 从此映射移除范围。
      Specified by:
      remove in interface RangeMap<K extends Comparable<? super K>, V>
      Parameters:
      range - the range to remove | 要移除的范围
    • clear

      public void clear()
      Description copied from interface: RangeMap
      Clear all mappings. 清除所有映射。
      Specified by:
      clear in interface RangeMap<K extends Comparable<? super K>, V>
    • 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