kyu

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2020 License: MIT Imports: 2 Imported by: 2

README

Kyu

Build Status Code Coverage Latest Version Documentation Go Report Card

Kyu provides various queue data structure implementations for Go.

It includes a min-max heap implementation that is a drop-in replacement for Go's container/heap package.

Documentation

Overview

Package kyu provides implementations of queues data structures with various different characteristics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Element

type Element struct {
	// Value is the value associated with the element.
	Value interface{}
	// contains filtered or unexported fields
}

Element is a container for a value on a queue.

It couple's the element's value with queue-specific meta-data that allows manipulation of the element while it is on the queue.

type PDeque

type PDeque struct {
	// Less returns true if a should be closer to the front of the queue than b.
	Less func(a, b interface{}) bool
	// contains filtered or unexported fields
}

PDeque is a double-ended priority queue.

It supports efficient inspection and removal of elements at both the front and back of the queue. The lowest elements appear towards the front of the queue.

func (*PDeque) Contains added in v0.2.0

func (q *PDeque) Contains(e *Element) bool

Contains returns true if e is in the queue.

func (*PDeque) Inverse

func (q *PDeque) Inverse() Queue

Inverse returns an inverted "view" of q, such that q.Inverse().Pop() is equivalent to q.PopBack(), etc.

func (*PDeque) IsBack

func (q *PDeque) IsBack(e *Element) bool

IsBack returns true if e is at the back of the queue.

func (*PDeque) IsFront

func (q *PDeque) IsFront(e *Element) bool

IsFront returns true if e is at the front of the queue.

func (*PDeque) Len

func (q *PDeque) Len() int

Len returns the number of elements in the queue.

func (*PDeque) Peek

func (q *PDeque) Peek() (e *Element, ok bool)

Peek returns the element at the front of the queue without removing it from the queue.

If the queue is empty, e is nil and ok is false.

func (*PDeque) PeekBack

func (q *PDeque) PeekBack() (e *Element, ok bool)

PeekBack returns the element at the back of the queue without removing it from the queue.

If the queue is empty, e is nil and ok is false.

func (*PDeque) Pop

func (q *PDeque) Pop() (v interface{}, ok bool)

Pop removes the element at the front of the queue and returns its value.

If the queue is empty, v is nil and ok is false.

func (*PDeque) PopBack

func (q *PDeque) PopBack() (v interface{}, ok bool)

PopBack removes the element at the back of the queue and returns its value.

If the queue is empty, v is nil and ok is false.

func (*PDeque) Push

func (q *PDeque) Push(v interface{}) *Element

Push adds a new value to the queue.

It returns the element that contains that value.

func (*PDeque) Remove

func (q *PDeque) Remove(e *Element)

Remove removes e from the queue.

func (*PDeque) Update

func (q *PDeque) Update(e *Element)

Update reorders the queue to reflect a change in e.Value that might cause e to occupy a different position within in the queue.

type PQueue

type PQueue struct {
	// Less returns true if a should be closer to the front of the queue than b.
	Less func(a, b interface{}) bool
	// contains filtered or unexported fields
}

PQueue is a priority queue.

It supports efficient inspection and removal of elements at the front of the queue. The lowest elements appear towards the front of the queue.

func (*PQueue) Contains added in v0.2.0

func (q *PQueue) Contains(e *Element) bool

Contains returns true if e is in the queue.

func (*PQueue) IsFront

func (q *PQueue) IsFront(e *Element) bool

IsFront returns true if e is at the front of the queue.

func (*PQueue) Len

func (q *PQueue) Len() int

Len returns the number of elements in the queue.

func (*PQueue) Peek

func (q *PQueue) Peek() (e *Element, ok bool)

Peek returns the element at the front of the queue without removing it from the queue.

If the queue is empty, e is nil and ok is false.

func (*PQueue) Pop

func (q *PQueue) Pop() (v interface{}, ok bool)

Pop removes the element at the front of the queue and returns its value.

If the queue is empty, v is nil and ok is false.

func (*PQueue) Push

func (q *PQueue) Push(v interface{}) *Element

Push adds a new value to the queue.

It returns the element that contains that value.

func (*PQueue) Remove

func (q *PQueue) Remove(e *Element)

Remove removes e from the queue.

func (*PQueue) Update

func (q *PQueue) Update(e *Element)

Update reorders the queue to reflect a change in e.Value that might cause e to occupy a different position within in the queue.

type Queue

type Queue interface {
	// Len returns the number of elements in the queue.
	Len() int

	// Push adds a new value to the queue.
	//
	// It returns the element that contains that value.
	Push(v interface{}) *Element

	// Peek returns the element at the front of the queue without removing it
	// from the queue.
	//
	// If the queue is empty, e is nil and ok is false.
	Peek() (e *Element, ok bool)

	// Pop removes the element at the front of the queue and returns its value.
	//
	// If the queue is empty, v is nil and ok is false.
	Pop() (v interface{}, ok bool)

	// Contains returns true if e is in the queue.
	Contains(e *Element) bool

	// IsFront returns true if e is at the front of the queue.
	IsFront(e *Element) bool

	// Update reorders the queue to reflect a change in e.Value that might cause
	// e to occupy a different position within in the queue.
	Update(e *Element)

	// Remove removes e from the queue.
	Remove(e *Element)
}

Queue is an interface for a queue.

The interface makes the distinction between a "value", which is the user-provided value to be placed on the queue, and an "element", which represents a value that has been placed on a queue.

Directories

Path Synopsis
Package mmheap provides a drop-in replacement for the container/heap package that provides min-max heap semantics.
Package mmheap provides a drop-in replacement for the container/heap package that provides min-max heap semantics.

Jump to

Keyboard shortcuts

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