priorityqueue

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2022 License: MIT Imports: 0 Imported by: 2

README

go-priorityqueue

Implements a generic Priority Queue in Golang (1.18)

Install

go get github.com/AlexandreChamard/go-priorityqueue

Examples

import (
    "github.com/AlexandreChamard/go-priorityqueue"
)

pqueue := priorityqueue.NewPriorityQueue(func(a, b int) bool { return a < b })

n := 10000

for i := n - 1; i >= 0; i-- {
    pqueue.Push(i)
}
for i := 0; i < n; i++ {
    fmt.Println(pqueue)
    if pqueue.Empty() {
        t.Fatalf("%d: pqueue.Empty(): expected %v got %v", i, false, pqueue.Empty())
    }
    if pqueue.Size() != n-i {
        t.Fatalf("%d: pqueue.Size(): expected %d got %d", i, n-i, pqueue.Size())
    }
    if pqueue.Front() != i {
        t.Fatalf("%d: pqueue.Front(): expected %d got %d", i, i, pqueue.Front())
    }
    pqueue.Pop()
}
if !pqueue.Empty() {
    t.Fatalf("pqueue.Empty(): should be empty at the end")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PriorityQueue

type PriorityQueue[T any] interface {
	Empty() bool
	Size() int
	Front() T
	Push(T)
	Pop()
}

func NewPriorityQueue

func NewPriorityQueue[T any](comp func(a, b T) bool) PriorityQueue[T]

Jump to

Keyboard shortcuts

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