pq

package module
Version: v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2021 License: MIT Imports: 1 Imported by: 0

README

go-ipfs-pq

standard-readme compliant GoDoc Build Status

go-ipfs-pq implements a priority queue.

Table of Contents

Install

go-ipfs-pq works like a regular Go module:

> go get github.com/ipfs/go-ipfs-pq

Usage

import "github.com/ipfs/go-ipfs-pq"

Check the GoDoc documentation

Contribute

PRs accepted.

Small note: If editing the README, please conform to the standard-readme specification.

License

MIT © Protocol Labs, Inc.

Documentation

Overview

Package pq implements a priority queue.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Elem

type Elem interface {
	// SetIndex stores the int index.
	SetIndex(int)
	// Index returns the last given by SetIndex(int).
	Index() int
}

Elem describes elements that can be added to the PQ. Clients must implement this interface.

type ElemComparator

type ElemComparator func(a, b Elem) bool

ElemComparator returns true if pri(a) > pri(b)

type PQ

type PQ interface {
	// Push adds the ele
	Push(Elem)
	// Pop removes and returns the highest priority Elem in PQ.
	Pop() Elem
	// Peek returns the highest priority Elem in PQ (without removing it).
	Peek() Elem
	// Remove removes the item at the given index from the PQ.
	Remove(index int) Elem
	// Len returns the number of elements in the PQ.
	Len() int
	// Update `fixes` the PQ.
	Update(index int)
}

PQ is a basic priority queue.

func New

func New(cmp ElemComparator) PQ

New creates a PQ with a client-supplied comparator.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL