toplist

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TopList

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

TopList store some elements in list with specified capacity, the oldest elements that exceed specified capacity will be discarded

func New

func New(capacity int) (*TopList, error)

New create a TopList with specified capacity and the capacity must be greater than zero, order by add time desc

func NewOrderByAsc

func NewOrderByAsc(capacity int) (*TopList, error)

NewOrderByAsc create a TopList with specified capacity and the capacity must be greater than zero, order by add time asc

func (*TopList) Add

func (tl *TopList) Add(element any)

Add add an element to the list

func (*TopList) Cap

func (tl *TopList) Cap() int

Cap returns the capacity of the list

func (*TopList) Get

func (tl *TopList) Get(index int) any

Get get an element by a specified index in the list, if the index is greater than TopList.Len or less than 0, return a nil element always

func (*TopList) Last

func (tl *TopList) Last() any

Last returns the last element of the list

func (*TopList) Len

func (tl *TopList) Len() int

Len returns the length of the list

func (*TopList) MarshalJSON

func (tl *TopList) MarshalJSON() (text []byte, err error)

MarshalJSON implement interface json.Marshaler

func (*TopList) Top

func (tl *TopList) Top(n int) (list []any)

Top returns the latest elements by top n

Jump to

Keyboard shortcuts

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