top

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2024 License: BSD-3-Clause Imports: 2 Imported by: 1

README

Package top implements a “top N” accumulator. See the API reference.

Documentation

Overview

Package top implements a “top N” accumulator.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TopN

type TopN[E any] struct {
	// contains filtered or unexported fields
}

A TopN keeps the top (greatest) N elements from a set of elements added incrementally.

func New

func New[E any](N int, cmp func(E, E) int) *TopN[E]

New creates a new TopN keeping the top (greatest) N elements according to the ordering function cmp.

func (*TopN[E]) Add

func (t *TopN[E]) Add(x E)

Add adds a new element to the set.

func (*TopN[E]) Take

func (t *TopN[E]) Take() []E

Take returns the top N elements among those added with TopN.Add. The order of elements that compare equal is unspecified. Take takes the elements out of t, resetting it for another collection.

Jump to

Keyboard shortcuts

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