Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // 跳表的最大层数。对于1000万数据量,根据公式 h = log₂(n)/2, // 大约需要 log₂(10⁷)/2 ≈ 12 层。请根据实际业务需求和数据量大小适当调整该值,以优化性能和空间利用。 // Maximum number of levels in the skip list. For 10 million elements, // using formula h = log₂(n)/2, we need approximately log₂(10⁷)/2 ≈ 12 levels. // Please adjust this value based on your actual business needs and data size to optimize performance and space utilization. MaxLevel = 12 // 用于随机层级生成的概率值,设置为0.25 // Probability used for random level generation, set to 0.25 Probability = 0.25 )
Functions ¶
Types ¶
type Ordered ¶
type Ordered interface { ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | ~float32 | ~float64 | ~string }
Ordered 接口定义了可用作键或值的类型约束 Ordered interface defines type constraints for keys and values
type RankList ¶
type RankList[K Ordered, V Ordered] struct { sync.RWMutex // contains filtered or unexported fields }
RankList 定义跳表的核心结构 提供线程安全的节点管理,支持插入、删除、查找、排名等功能 RankList defines the core structure of the skip list Provides thread-safe node management and supports insertion, deletion, retrieval, and ranking functionalities
func (*RankList[K, V]) Del ¶
Del 从跳表中删除指定键的节点。 如果键存在并且节点被删除,返回true;如果键不存在,返回false。 Del removes the node with the specified key from the skip list. Returns true if the key exists and the node is deleted, false if the key does not exist.
func (*RankList[K, V]) Get ¶
Get 根据键获取节点的值 如果键存在并且节点被删除,返回true;如果键不存在,返回false。 Get retrieves the value associated with the key Returns true if the key exists and the node is deleted, false if the key does not exist.
func (*RankList[K, V]) Length ¶ added in v1.0.1
Length 返回跳表中当前元素的数量。 Length returns the current number of elements in the skip list.
func (*RankList[K, V]) Range ¶ added in v1.0.1
Range 获取指定排名区间内的榜单项(不包含END) 返回指定范围内的条目列表。 Range retrieves the entries within the specified rank range (excluding END) Returns a list of entries within the specified range.