sorter

package
v1.11.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultIndexGap 默认稀疏索引间隔
	DefaultIndexGap = 1000
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Item added in v1.11.3

type Item struct {
	ID      int64
	SortKey int64
}

Item 排序更新项

type ReorderPlan

type ReorderPlan struct {
	// Unchanged 是否未发生位置变化(原地拖拽,无需写库)
	Unchanged bool
	// NeedRebalance 是否需要全局重平衡
	NeedRebalance bool
	// NewSortKey 单条更新时的目标 SortKey(快速路径)
	NewSortKey int64
	// Items 批量重平衡更新项列表(慢路径)
	Items []Item
}

ReorderPlan 重排计算方案

func Reorder added in v1.11.3

func Reorder[E Sortable](elements []E, draggedID, targetPosition int64) ReorderPlan

Reorder 使用默认步长计算重排方案

func ReorderWithGap added in v1.11.3

func ReorderWithGap[E Sortable](elements []E, draggedID, targetPosition, gap int64) ReorderPlan

ReorderWithGap 自定义稀疏步长计算重排方案

type Sortable

type Sortable interface {
	GetID() int64
	GetSortKey() int64
}

Sortable 可排序元素接口

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL