sortedwindow

package
v0.0.0-...-2627f95 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithLimit

func WithLimit(l int) option

WithLimit sets the size limit for the sorted window.

Types

type Comparator

type Comparator func(a, b interface{}) int

Comparator is a function that compares two values return 0 if they are equal return -1 if a < b return 1 if a > b

type Iterator

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

Iterator is an iterator for a sorted window

func (*Iterator) Next

func (iter *Iterator) Next() bool

Next advances the iterator. It must be called once to advance to the first position. It returns true if there is another value available, false otherwise

func (*Iterator) Value

func (iter *Iterator) Value() interface{}

Value returns the value at the current position

type SortedMinWindow

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

SortedMinWindow is used to sort a stream of values when that stream may be too large to buffer in memory If limit is positive it sets the window size. If limit is negative or zero there is no limit and the window will grow to hold the entire data set in memory.

func New

func New(comparator Comparator, opts ...option) *SortedMinWindow

New creates a new SortedMinWindow.

func (*SortedMinWindow) Insert

func (sortedWindow *SortedMinWindow) Insert(obj interface{})

Insert attempts to insert obj into the window. If limit is <= 0 it will be inserted. If limit > 0 and size has not yet hit limit then it will be inserted. If limit > 0 and size has hit limit and obj >= the max value in the window then it will not be inserted. If limit > 0 and size has hit limit and obj < the max value in the window then it will be inserted and the max value will be removed.

func (*SortedMinWindow) Iterator

func (sortedWindow *SortedMinWindow) Iterator() *Iterator

Iterator returns an iterator for the window that returns values in ascending order

func (*SortedMinWindow) Size

func (sortedWindow *SortedMinWindow) Size() int

Size returns the number of elements in the window

Directories

Path Synopsis
Package redblacktree implements a red-black tree.
Package redblacktree implements a red-black tree.

Jump to

Keyboard shortcuts

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