pq

package
v0.0.0-...-d229d73 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2024 License: MIT Imports: 1 Imported by: 0

README

优先队列(Priority Queue)

优先队列中的每个元素都有各自的优先级,优先级最高的元素最先得到服务;优先级相同的元素按照其在优先队列中的顺序得到服务。优先队列往往用堆来实现。

操作

优先队列至少需要支持下述操作:

  1. 插入带优先级的元素(insert_with_priority);
  2. 取出具有最高优先级的元素(pull_highest_priority_element);
  3. 查看最高优先级的元素(peek):O(1) 时间复杂度。

其它可选的操作:

  1. 检查优先级高的一批元素;
  2. 清空优先队列;
  3. 批插入一批元素;
  4. 合并多个优先队列;
  5. 调整一个元素的优先级。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Element

type Element struct {
	Value    interface{}
	Priority int
}

func NewElement

func NewElement(value interface{}, priority int) (e *Element)

func (Element) GreaterThan

func (e Element) GreaterThan(hel Element) bool

type PQ

type PQ struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func PQConstructor

func PQConstructor() (pq *PQ)

func (*PQ) Extract

func (pq *PQ) Extract() (el Element)

func (*PQ) Insert

func (pq *PQ) Insert(el Element)

func (*PQ) Len

func (pq *PQ) Len() int

func (*PQ) Peek

func (pq *PQ) Peek() (el Element)

Jump to

Keyboard shortcuts

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