sorter

package
v1.11.5 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: MIT Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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