genericqueue

package
v0.0.0-...-3a970f8 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2022 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

This example demonstrates a priority queue built using the heap interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Interface

type Interface[T any] interface {
	Push(item *Item[T])
	Update(item *Item[T], value T, priority int)
	Pop() *Item[T]
	Len() int
	Arr() PriorityQueue[T]
}

func New

func New[T any](items ...*Item[T]) Interface[T]

type Item

type Item[T any] struct {
	Value    T
	Priority int
	// contains filtered or unexported fields
}

An Item is something we manage in a priority queue.

func (*Item[T]) Pos

func (i *Item[T]) Pos() int

func (*Item[T]) SetId

func (i *Item[T]) SetId(id int)

type PriorityQueue

type PriorityQueue[T any] []*Item[T]

func (PriorityQueue[T]) Len

func (pq PriorityQueue[T]) Len() int

func (PriorityQueue[T]) Less

func (pq PriorityQueue[T]) Less(i, j int) bool

func (*PriorityQueue[T]) Pop

func (pq *PriorityQueue[T]) Pop() any

func (*PriorityQueue[T]) Push

func (pq *PriorityQueue[T]) Push(x any)

func (PriorityQueue[T]) Swap

func (pq PriorityQueue[T]) Swap(i, j int)

func (*PriorityQueue[T]) Update

func (pq *PriorityQueue[T]) Update(item *Item[T], value T, priority int)

Update modifies the priority and value of an Item in the queue.

Jump to

Keyboard shortcuts

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