Bucket

package
v0.3.12 Latest Latest
Warning

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

Go to latest
Published: May 29, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func KeepIfBuckets

func KeepIfBuckets[T any](buckets map[int]*Bucket[T], f slext.PredicateFilter[T]) map[int]*Bucket[T]

KeepIfBuckets keeps the elements in the buckets that satisfy the given predicate filter.

Parameters:

  • buckets: buckets to filter.
  • f: predicate filter to use.

Returns:

  • map[int]*Bucket: the filtered buckets.

func MakeBuckets

func MakeBuckets[T any](elems []T, f func(T) int) map[int]*Bucket[T]

MakeBuckets creates a map of buckets from the given elements using the given function.

Parameters:

  • elems: elements to add to the buckets.
  • f: function to use to determine the size of the buckets.

Returns:

  • map[int]*Bucket: the map of buckets.

func SortBuckets

func SortBuckets[T any](buckets map[int]*Bucket[T], f SortFunc[T])

SortBuckets sorts the buckets using the given function.

Parameters:

  • buckets: buckets to sort.
  • f: comparison function to use.

func ViewTopNBuckets

func ViewTopNBuckets[T any](buckets map[int]*Bucket[T], n int) map[int]*Bucket[T]

ViewTopNBuckets returns the top N buckets.

Parameters:

  • buckets: buckets to filter.
  • n: number of buckets to return.

Returns:

  • map[int]*Bucket: the top N buckets.

Types

type Bucket

type Bucket[T any] struct {
	// contains filtered or unexported fields
}

Bucket represents a bucket of elements.

func NewBucket

func NewBucket[T any](elements []T) *Bucket[T]

NewBucket creates a new bucket of elements.

Parameters:

  • elements: elements to add to the bucket.

Returns:

  • *Bucket: the new bucket.

func (*Bucket[T]) Add

func (b *Bucket[T]) Add(element T)

Add adds a element to the bucket.

Parameters:

  • element: element to add.

func (*Bucket[T]) GetSize

func (b *Bucket[T]) GetSize() int

GetSize returns the size of the bucket.

Returns:

  • int: the size of the bucket.

func (*Bucket[T]) InsertionSort

func (b *Bucket[T]) InsertionSort(f SortFunc[T])

InsertionSort sorts the elements in the bucket using the given comparison function.

Parameters:

  • f: comparison function to use.

func (*Bucket[T]) Iterator

func (b *Bucket[T]) Iterator() ui.Iterater[T]

Iterator implements the Iterator method of the Iterable interface.

func (*Bucket[T]) Limit

func (b *Bucket[T]) Limit(n int) *Bucket[T]

Limit limits the number of elements in the bucket.

Parameters:

  • n: number of elements to keep.

Returns:

  • *Bucket: the bucket.

func (*Bucket[T]) LinearKeep

func (b *Bucket[T]) LinearKeep(f us.PredicateFilter[T])

LinearKeep keeps the elements in the bucket that satisfy the given predicate filter.

Parameters:

  • f: predicate filter to use.

type SortFunc

type SortFunc[T any] func(b1, b2 T) bool

SortFunc is a function type that defines a comparison function for branches.

Parameters:

  • b1: first branch to compare.
  • b2: second branch to compare.

Returns:

  • bool: true if the first branch is less than the second branch, false otherwise.

Jump to

Keyboard shortcuts

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