Documentation
¶
Index ¶
Constants ¶
View Source
const (
// DefaultIndexGap 默认稀疏索引间隔
DefaultIndexGap = 1000
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ReorderPlan ¶
type ReorderPlan[T SortItem] struct { // NeedRebalance 是否需要重平衡 NeedRebalance bool // NewSortKey 单个元素的新 SortKey(快速路径) NewSortKey int64 // Items 批量更新的元素列表(慢路径) Items []T }
ReorderPlan 重排执行计划 NOTE: T 为排序项类型,必须满足 SortItem 约束
type Sorter ¶
Sorter 通用排序器 NOTE: E 为元素类型(实现 Sortable), T 为排序项类型(实现 SortItem)
func NewSorter ¶
NewSorter 创建排序器 convertFunc: 将元素转换为排序项,用于重平衡场景 例如: func(attr Attribute, idx int) AttributeSortItem { ... }
func (*Sorter[E, T]) PlanReorder ¶
func (s *Sorter[E, T]) PlanReorder(elements []E, draggedElem E, targetPosition int64) ReorderPlan[T]
PlanReorder 计算重排方案(核心算法,纯函数) elements: 目标分组/列表中的所有元素 draggedElem: 被拖拽的元素 targetPosition: 目标位置 (0-based)
func (*Sorter[E, T]) WithIndexGap ¶
WithIndexGap 设置索引间隔
Click to show internal directories.
Click to hide internal directories.