Discover Packages
rsc.io/top
package
module
Version:
v1.0.2
Opens a new window with list of versions in this module.
Published: Jun 4, 2024
License: BSD-3-Clause
Opens a new window with license information.
Imports: 2
Opens a new window with list of imports.
Imported by: 1
Opens a new window with list of known importers.
README
README
¶
Package top implements a “top N” accumulator.
See the API reference .
Expand ▾
Collapse ▴
Documentation
¶
Package top implements a “top N” accumulator.
type TopN[E any ] struct {
}
A TopN keeps the top (greatest) N elements from
a set of elements added incrementally.
New creates a new TopN keeping the top (greatest) N elements
according to the ordering function cmp.
func (t *TopN [E]) Add(x E)
Add adds a new element to the set.
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.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.