Class SkipList<K,V>
java.lang.Object
cloud.opencode.base.collections.tree.SkipList<K,V>
- Type Parameters:
K- key type | 键类型V- value type | 值类型
- All Implemented Interfaces:
Serializable, Iterable<SkipList.Entry<K,V>>
public final class SkipList<K,V>
extends Object
implements Iterable<SkipList.Entry<K,V>>, Serializable
SkipList - Skip List Implementation
SkipList - 跳表实现
A probabilistic data structure providing O(log n) search, insert, and delete.
提供 O(log n) 搜索、插入和删除的概率数据结构。
Features | 主要功能:
- O(log n) operations - O(log n) 操作
- Sorted order - 排序顺序
- Range queries - 范围查询
- Simpler than balanced trees - 比平衡树简单
Usage Examples | 使用示例:
SkipList<Integer, String> skipList = SkipList.create();
skipList.put(1, "one");
skipList.put(5, "five");
skipList.put(3, "three");
String value = skipList.get(3); // "three"
// Iteration in sorted order - 按排序顺序迭代
for (SkipList.Entry<Integer, String> entry : skipList) {
System.out.println(entry.getKey() + ": " + entry.getValue());
}
Performance | 性能特性:
- put: O(log n) average - put: O(log n) 平均
- get: O(log n) average - get: O(log n) 平均
- remove: O(log n) average - remove: O(log n) 平均
Security | 安全性:
- Thread-safe: No - 否
- Null-safe: No (key must not be null) - 否(键不能为null)
- Since:
- JDK 25, opencode-base-collections V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear this skip list.booleancontainsKey(K key) Check if the key exists.static <K extends Comparable<? super K>, V>
SkipList<K, V> create()Create an empty SkipList with natural ordering.static <K,V> SkipList <K, V> create(Comparator<? super K> comparator) Create an empty SkipList with custom comparator.firstKey()Get the first (smallest) key.Get the value for a key.booleanisEmpty()Check if this skip list is empty.iterator()lastKey()Get the last (largest) key.Put a key-value pair.Remove a key.intsize()Return the size of this skip list.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Method Details
-
create
Create an empty SkipList with natural ordering. 创建自然排序的空 SkipList。- Type Parameters:
K- key type | 键类型V- value type | 值类型- Returns:
- new empty SkipList | 新空 SkipList
-
create
Create an empty SkipList with custom comparator. 创建自定义比较器的空 SkipList。- Type Parameters:
K- key type | 键类型V- value type | 值类型- Parameters:
comparator- the comparator | 比较器- Returns:
- new empty SkipList | 新空 SkipList
-
put
-
get
-
containsKey
Check if the key exists. 检查键是否存在。- Parameters:
key- the key | 键- Returns:
- true if exists | 如果存在则返回 true
-
remove
-
size
public int size()Return the size of this skip list. 返回此跳表的大小。- Returns:
- the size | 大小
-
isEmpty
public boolean isEmpty()Check if this skip list is empty. 检查此跳表是否为空。- Returns:
- true if empty | 如果为空则返回 true
-
clear
public void clear()Clear this skip list. 清空此跳表。 -
firstKey
-
lastKey
-
iterator
-