priorityqueue

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

README

priorityQueue

Priority queue with Generics support

  • Supports only cmp.Ordered types

usage

var pq Queue[int]

pq.Push(2)
pq.Push(3)
pq.Push(1)

for len(pq) != 0 {
    e = pq.Pop()
    fmt.Println(e)
}
type pair struct {
	x, y int
}

pq := New[pair](func(i, j pair) bool {
	return i.x < j.x
})

pq.Push(pair{2, 1})
pq.Push(pair{3, -1})
pq.Push(pair{1, 10})

for len(pq) != 0 {
    e = pq.Pop()
    fmt.Println(e)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

type Queue[T cmp.Ordered] []T

Queue ... 実装例

func (Queue[T]) Len

func (q Queue[T]) Len() int

func (Queue[T]) Less

func (q Queue[T]) Less(i, j int) bool

func (*Queue[T]) Pop

func (q *Queue[T]) Pop() T

func (*Queue[T]) Push

func (q *Queue[T]) Push(x T)

func (Queue[T]) Swap

func (q Queue[T]) Swap(i, j int)

type QueueL added in v0.1.1

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

Queue ... 実装例

func New added in v0.1.1

func New[T any](less func(i, j T) bool) QueueL[T]

func (QueueL[T]) Len added in v0.1.1

func (q QueueL[T]) Len() int

func (*QueueL[T]) Pop added in v0.1.1

func (q *QueueL[T]) Pop() (T, bool)

func (*QueueL[T]) Push added in v0.1.1

func (q *QueueL[T]) Push(x T)

func (QueueL[T]) Swap added in v0.1.1

func (q QueueL[T]) Swap(i, j int)

Jump to

Keyboard shortcuts

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