Class TreeRangeSet<C extends Comparable<? super C>>
java.lang.Object
cloud.opencode.base.collections.specialized.TreeRangeSet<C>
- Type Parameters:
C- the type of range endpoints | 范围端点类型
- All Implemented Interfaces:
RangeSet<C>, Serializable
public final class TreeRangeSet<C extends Comparable<? super C>>
extends Object
implements RangeSet<C>, Serializable
TreeRangeSet - Tree-based Range Set Implementation
TreeRangeSet - 基于树的范围集合实现
A range set 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 | 使用示例:
TreeRangeSet<Integer> rangeSet = TreeRangeSet.create();
rangeSet.add(Range.closed(1, 10));
rangeSet.add(Range.closed(5, 15)); // coalesces to [1, 15]
boolean contains = rangeSet.contains(5); // true
Range<Integer> range = rangeSet.rangeContaining(5); // [1, 15]
Performance | 性能特性:
- add: O(log n) - add: O(log n)
- remove: O(log n) - remove: O(log n)
- contains: O(log n) - contains: O(log n)
- rangeContaining: O(log n) - rangeContaining: O(log n)
Security | 安全性:
- Thread-safe: No - 线程安全: 否
- Null-safe: No (nulls not allowed) - 空值安全: 否(不允许空值)
- Since:
- JDK 25, opencode-base-collections V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a range to this set.voidAdd all ranges from another range set.Return all ranges as a descending set.asRanges()Return all ranges as a set.voidclear()Clear all ranges.Return the complement of this range set.booleanCheck if the value is contained in any range.static <C extends Comparable<? super C>>
TreeRangeSet<C> create()Create an empty TreeRangeSet.static <C extends Comparable<? super C>>
TreeRangeSet<C> Create a TreeRangeSet with the given ranges.booleanCheck if this range set encloses the given range.booleanenclosesAll(RangeSet<C> other) Check if this range set encloses all ranges in the other set.booleaninthashCode()booleanintersects(Range<C> otherRange) Check if this range set intersects the given range.booleanisEmpty()Check if this range set is empty.rangeContaining(C value) Return the range containing the value, or null.voidRemove a range from this set.voidRemove all ranges in another range set.span()Return the minimal range that encloses all ranges.subRangeSet(Range<C> view) Return a sub range set within the given range.toString()
-
Method Details
-
create
Create an empty TreeRangeSet. 创建空 TreeRangeSet。- Type Parameters:
C- endpoint type | 端点类型- Returns:
- new empty TreeRangeSet | 新空 TreeRangeSet
-
create
Create a TreeRangeSet with the given ranges. 使用给定范围创建 TreeRangeSet。- Type Parameters:
C- endpoint type | 端点类型- Parameters:
ranges- the ranges | 范围- Returns:
- new TreeRangeSet | 新 TreeRangeSet
-
contains
-
rangeContaining
Description copied from interface:RangeSetReturn the range containing the value, or null. 返回包含该值的范围,如果不存在则返回 null。- Specified by:
rangeContainingin interfaceRangeSet<C extends Comparable<? super C>>- Parameters:
value- the value | 值- Returns:
- the containing range, or null | 包含的范围,或 null
-
encloses
-
enclosesAll
Description copied from interface:RangeSetCheck if this range set encloses all ranges in the other set. 检查此范围集合是否完全包含另一个集合中的所有范围。- Specified by:
enclosesAllin interfaceRangeSet<C extends Comparable<? super C>>- Parameters:
other- the other range set | 另一个范围集合- Returns:
- true if all enclosed | 如果全部包含则返回 true
-
intersects
Description copied from interface:RangeSetCheck if this range set intersects the given range. 检查此范围集合是否与给定范围相交。- Specified by:
intersectsin interfaceRangeSet<C extends Comparable<? super C>>- Parameters:
otherRange- the range to check | 要检查的范围- Returns:
- true if intersects | 如果相交则返回 true
-
isEmpty
-
asRanges
-
asDescendingSetOfRanges
Description copied from interface:RangeSetReturn all ranges as a descending set. 以降序集合形式返回所有范围。- Specified by:
asDescendingSetOfRangesin interfaceRangeSet<C extends Comparable<? super C>>- Returns:
- the descending set of ranges | 降序范围集合
-
complement
Description copied from interface:RangeSetReturn the complement of this range set. 返回此范围集合的补集。- Specified by:
complementin interfaceRangeSet<C extends Comparable<? super C>>- Returns:
- the complement | 补集
-
subRangeSet
Description copied from interface:RangeSetReturn a sub range set within the given range. 返回给定范围内的子范围集合。- Specified by:
subRangeSetin interfaceRangeSet<C extends Comparable<? super C>>- Parameters:
view- the viewing range | 视图范围- Returns:
- the sub range set | 子范围集合
-
span
-
add
-
remove
-
addAll
-
removeAll
-
clear
-
equals
-
hashCode
-
toString
-