queue

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

func Compare[T constraints.Ordered](v1, v2 T) int

Types

type Comparable

type Comparable interface {
	CompareTo(Comparable) int
}

Comparable method CompareTo(Comparable) should return a negative number when v1 < v2, a positive number when v1 > v2 and zero when v1 == v2.

type Container

type Container[T Comparable] struct {
	Items []T  // container data
	Desc  bool // asc or desc, default asc.
}

func (Container[T]) Len

func (c Container[T]) Len() int

Len implement heap.Interface.

func (Container[T]) Less

func (c Container[T]) Less(i, j int) bool

Less implement heap.Interface.

func (*Container[T]) Pop

func (c *Container[T]) Pop() any

Pop implement heap.Interface.

func (*Container[T]) Push

func (c *Container[T]) Push(x any)

Push implement heap.Interface.

func (Container[T]) Swap

func (c Container[T]) Swap(i, j int)

Swap implement heap.Interface.

type Float32

type Float32 float32

func (Float32) CompareTo

func (v1 Float32) CompareTo(v2 Comparable) int

type Float64

type Float64 float64

func (Float64) CompareTo

func (v1 Float64) CompareTo(v2 Comparable) int

type Int

type Int int

func (Int) CompareTo

func (v1 Int) CompareTo(v2 Comparable) int

type Int16

type Int16 int16

func (Int16) CompareTo

func (v1 Int16) CompareTo(v2 Comparable) int

type Int32

type Int32 int32

func (Int32) CompareTo

func (v1 Int32) CompareTo(v2 Comparable) int

type Int64

type Int64 int64

func (Int64) CompareTo

func (v1 Int64) CompareTo(v2 Comparable) int

type Int8

type Int8 int8

func (Int8) CompareTo

func (v1 Int8) CompareTo(v2 Comparable) int

type PriorityQueue

type PriorityQueue[T Comparable] struct {
	// contains filtered or unexported fields
}

PriorityQueue represents an unbounded priority queue based on a priority heap. It implements heap.Interface.

func NewPriorityQueue

func NewPriorityQueue[T Comparable](maxHeap bool, items ...T) *PriorityQueue[T]

NewPriorityQueue initializes and returns an Queue, default min heap.

func (*PriorityQueue[T]) Add

func (pq *PriorityQueue[T]) Add(item T)

Add inserts the specified element into this priority queue.

func (*PriorityQueue[T]) Clear

func (pq *PriorityQueue[T]) Clear()

Clear removes all the elements from this priority queue.

func (*PriorityQueue[T]) Contains

func (pq *PriorityQueue[T]) Contains(val T) bool

Contains returns true if this queue contains the specified element.

func (*PriorityQueue[T]) IsEmpty

func (pq *PriorityQueue[T]) IsEmpty() bool

IsEmpty returns true if this list contains no elements.

func (*PriorityQueue[T]) Len

func (pq *PriorityQueue[T]) Len() int

Len returns the length of this priority queue.

func (*PriorityQueue[T]) Peek

func (pq *PriorityQueue[T]) Peek() (val T, exist bool)

Peek retrieves, but does not remove, the head of this queue, or return nil if this queue is empty.

func (*PriorityQueue[T]) Poll

func (pq *PriorityQueue[T]) Poll() (val T, exist bool)

Poll retrieves and removes the head of the this queue, or return nil if this queue is empty.

func (*PriorityQueue[T]) Remove

func (pq *PriorityQueue[T]) Remove(val T)

Remove a single instance of the specified element from this queue, if it is present. It returns false if the target value isn't present, otherwise returns true.

type String

type String string

func (String) CompareTo

func (v1 String) CompareTo(v2 Comparable) int

type Time

type Time time.Time

func (Time) CompareTo

func (v1 Time) CompareTo(v2 Comparable) int

type Uint

type Uint uint

func (Uint) CompareTo

func (v1 Uint) CompareTo(v2 Comparable) int

type Uint16

type Uint16 uint16

func (Uint16) CompareTo

func (v1 Uint16) CompareTo(v2 Comparable) int

type Uint32

type Uint32 uint32

func (Uint32) CompareTo

func (v1 Uint32) CompareTo(v2 Comparable) int

type Uint64

type Uint64 uint64

func (Uint64) CompareTo

func (v1 Uint64) CompareTo(v2 Comparable) int

type Uint8

type Uint8 uint8

func (Uint8) CompareTo

func (v1 Uint8) CompareTo(v2 Comparable) int

type Uintptr

type Uintptr uintptr

func (Uintptr) CompareTo

func (v1 Uintptr) CompareTo(v2 Comparable) int

Jump to

Keyboard shortcuts

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