heap

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Elem

type Elem[E any, W constraints.Ordered] struct {
	Value  E
	Weight W
}

type PriorityQueue

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

PriorityQueue represents the priority queue.

func NewPriorityQueue

func NewPriorityQueue(desc bool) *PriorityQueue

NewPriorityQueue initializes an empty priority queue.

func (*PriorityQueue) Clone

func (p *PriorityQueue) Clone() *PriorityQueue

func (*PriorityQueue) Elems

func (p *PriorityQueue) Elems() []Elem[int32, float32]

func (*PriorityQueue) Len

func (e *PriorityQueue) Len() int

func (*PriorityQueue) Less

func (e *PriorityQueue) Less(i, j int) bool

func (*PriorityQueue) Peek

func (p *PriorityQueue) Peek() (int32, float32)

func (*PriorityQueue) Pop

func (p *PriorityQueue) Pop() (int32, float32)

Pop removes the element with the highest priority from the queue and returns it. In case of an empty queue, an error is returned.

func (*PriorityQueue) Push

func (p *PriorityQueue) Push(v int32, weight float32)

Push inserts a new element into the queue. No action is performed on duplicate elements.

func (*PriorityQueue) Reverse

func (p *PriorityQueue) Reverse() *PriorityQueue

func (*PriorityQueue) Swap

func (e *PriorityQueue) Swap(i, j int)

func (*PriorityQueue) Values

func (p *PriorityQueue) Values() []int32

type TopKFilter

type TopKFilter[T any, W constraints.Ordered] struct {
	// contains filtered or unexported fields
}

TopKFilter filters out top k items with maximum weights.

func NewTopKFilter

func NewTopKFilter[T any, W constraints.Ordered](k int) *TopKFilter[T, W]

NewTopKFilter creates a top k filter.

func (*TopKFilter) Len

func (e *TopKFilter) Len() int

func (*TopKFilter) Less

func (e *TopKFilter) Less(i, j int) bool

func (*TopKFilter) Pop

func (e *TopKFilter) Pop() interface{}

func (*TopKFilter[T, W]) PopAll

func (filter *TopKFilter[T, W]) PopAll() ([]T, []W)

PopAll pops all items in the filter with decreasing order.

func (*TopKFilter[T, W]) Push

func (filter *TopKFilter[T, W]) Push(item T, weight W)

Push pushes the element x onto the heap. The complexity is O(log n) where n = h.Count().

func (*TopKFilter) Swap

func (e *TopKFilter) Swap(i, j int)

Jump to

Keyboard shortcuts

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