sorters

package
v0.20.1-0...-1759310 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetTopNRows

func GetTopNRows(ctx *sql.Context, iter sql.RowIter, sortConditions sql.SortConditions, n int64) ([]sql.Row, int64, error)

GetTopNRows uses a Top-N Heap Sort to find the top (min) N rows in a RowIter. It inserts each row of the iter into the max-heap, popping the max row if the size of the heap exceeds N such that the heap only contains the N min rows. At the end, it pops the contents of the heap and returns them in min-first order.

Types

type RowSorter

type RowSorter struct {
	// contains filtered or unexported fields
}

RowSorter is a sorter implementation for Row slices using SortFields for the comparison. RowSorter can act as simply a container for sort conditions, or as a sorter for a slice of rows. If the latter, it caches the evaluated sort keys for each row to avoid re-evaluating them during sorting, which is necessary for correctness and desirable for performance.

func NewRowSorter

func NewRowSorter(ctx *sql.Context, sortConditions sql.SortConditions) *RowSorter

NewRowSorter creates a RowSorter for the given sort conditions

func NewRowSorterWithRows

func NewRowSorterWithRows(ctx *sql.Context, sortConditions sql.SortConditions, rows []sql.Row) *RowSorter

NewRowSorterWithRows creates a RowSorter for the given sort conditions and rows.

func (*RowSorter) CompareKeys

func (s *RowSorter) CompareKeys(a, b []interface{}) int

CompareKeys compares two sort keys produced by EvalKey based on s.sortConditions. Either key may be nil (a failed evaluation), in which case the comparison result is 0.

func (*RowSorter) EvalKey

func (s *RowSorter) EvalKey(row sql.Row) []interface{}

EvalKey evaluates the sort condition expressions for the given row, returning the resulting sort key. If any expression fails to evaluate, EvalKey records the error (see GetError) and returns nil.

func (*RowSorter) GetError

func (s *RowSorter) GetError() error

func (*RowSorter) Len

func (s *RowSorter) Len() int

Len implements sort.Interface

func (*RowSorter) Less

func (s *RowSorter) Less(i, j int) bool

Less implements sort.Interface interface.

func (*RowSorter) Swap

func (s *RowSorter) Swap(i, j int)

Swap implements sort.Interface

Jump to

Keyboard shortcuts

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