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 ¶
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 ¶
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.