queues

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2023 License: MIT Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArrayDeque added in v0.0.2

type ArrayDeque[T any] struct {
	// contains filtered or unexported fields
}

ArrayDeque is the array implementation of Deque, its ability of dynamically growing depends on the go slice implementation.

func NewArrayDequeue added in v0.0.2

func NewArrayDequeue[T any](size int) *ArrayDeque[T]

func (*ArrayDeque[T]) Clear added in v0.0.2

func (queue *ArrayDeque[T]) Clear()

func (*ArrayDeque[T]) Iterator added in v0.0.2

func (queue *ArrayDeque[T]) Iterator() containers.IndexIterator[T]

func (*ArrayDeque[T]) LPush added in v0.0.2

func (queue *ArrayDeque[T]) LPush(es ...T)

LPush pushed an item to the queue left end

func (*ArrayDeque[T]) Peek added in v0.0.2

func (queue *ArrayDeque[T]) Peek() (_ T, _ bool)

Peek represents RPeek, returns the first item of the queue right end

func (*ArrayDeque[T]) Pop added in v0.0.2

func (queue *ArrayDeque[T]) Pop() (_ T, _ bool)

Pop represents LPop, pop the first item of the queue left end

func (*ArrayDeque[T]) Push added in v0.0.2

func (queue *ArrayDeque[T]) Push(es ...T)

Push represents RPush, push an item to the queue right end

func (*ArrayDeque[T]) RPeek added in v0.0.2

func (queue *ArrayDeque[T]) RPeek() (_ T, _ bool)

RPeek returns the first item from queue right end.

func (*ArrayDeque[T]) RPop added in v0.0.2

func (queue *ArrayDeque[T]) RPop() (_ T, _ bool)

RPop pops the first item from queue right end.

func (*ArrayDeque[T]) Size added in v0.0.2

func (queue *ArrayDeque[T]) Size() int

func (*ArrayDeque[T]) String added in v0.0.2

func (queue *ArrayDeque[T]) String() string

func (*ArrayDeque[T]) Values added in v0.0.2

func (queue *ArrayDeque[T]) Values() []T

type ArrayQueue

type ArrayQueue[T any] struct {
	// contains filtered or unexported fields
}

ArrayQueue implements by slice, one of the most easily implementation of Queue

func NewArrayQueue

func NewArrayQueue[T any](capacity int) *ArrayQueue[T]

func (*ArrayQueue[T]) Clear

func (queue *ArrayQueue[T]) Clear()

func (*ArrayQueue[T]) Iterator

func (queue *ArrayQueue[T]) Iterator() containers.IndexIterator[T]

func (*ArrayQueue[T]) Peek

func (queue *ArrayQueue[T]) Peek() (_ T, _ bool)

func (*ArrayQueue[T]) Pop

func (queue *ArrayQueue[T]) Pop() (_ T, _ bool)

func (*ArrayQueue[T]) Push

func (queue *ArrayQueue[T]) Push(es ...T)

func (*ArrayQueue[T]) Size

func (queue *ArrayQueue[T]) Size() int

func (*ArrayQueue[T]) String

func (queue *ArrayQueue[T]) String() string

func (*ArrayQueue[T]) Values

func (queue *ArrayQueue[T]) Values() []T

type Deque added in v0.0.2

type Deque[T any] interface {
	Queue[T]
	// LPush push an item to the queue left end
	LPush(es ...T)
	// RPeek returns the first item from the queue right end
	RPeek() (T, bool)
	// RPop pop the first item from the queue right end
	RPop() (T, bool)
}

Deque represents the double-end queue, which could push item and pop item in both left and right end.

type LinkedQueue added in v0.0.3

type LinkedQueue[T any] struct {
	// contains filtered or unexported fields
}

LinkedQueue implements the Queue interface and Deque interface. It is different from ArrayDeque because it is based on lists.LinkedList, so no need to consider capacity of growing and shrinking.

func NewLinkedQueue added in v0.0.3

func NewLinkedQueue[T any]() *LinkedQueue[T]

func (*LinkedQueue[T]) Clear added in v0.0.3

func (l *LinkedQueue[T]) Clear()

func (*LinkedQueue[T]) Iterator added in v0.0.3

func (l *LinkedQueue[T]) Iterator() containers.IndexIterator[T]

func (*LinkedQueue[T]) LPush added in v0.0.3

func (l *LinkedQueue[T]) LPush(es ...T)

func (*LinkedQueue[T]) Peek added in v0.0.3

func (l *LinkedQueue[T]) Peek() (T, bool)

func (*LinkedQueue[T]) Pop added in v0.0.3

func (l *LinkedQueue[T]) Pop() (T, bool)

func (*LinkedQueue[T]) Push added in v0.0.3

func (l *LinkedQueue[T]) Push(es ...T)

func (*LinkedQueue[T]) RPeek added in v0.0.3

func (l *LinkedQueue[T]) RPeek() (T, bool)

func (*LinkedQueue[T]) RPop added in v0.0.3

func (l *LinkedQueue[T]) RPop() (T, bool)

func (*LinkedQueue[T]) Size added in v0.0.3

func (l *LinkedQueue[T]) Size() int

func (*LinkedQueue[T]) String added in v0.0.3

func (l *LinkedQueue[T]) String() string

func (*LinkedQueue[T]) Values added in v0.0.3

func (l *LinkedQueue[T]) Values() []T

type PriorityQueue

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

PriorityQueue implements by heap

func NewPriorityQueue

func NewPriorityQueue[T any](capacity int, compare containers.Compare[T]) *PriorityQueue[T]

NewPriorityQueue defaults use binary heap to implement

func NewPriorityQueueWith

func NewPriorityQueueWith[T any](heap heaps.Heap[T]) *PriorityQueue[T]

NewPriorityQueueWith returns a PriorityQueue implemented by the given custom heap

func (*PriorityQueue[T]) Clear

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

func (*PriorityQueue[T]) Iterator

func (p *PriorityQueue[T]) Iterator() containers.IndexIterator[T]

func (*PriorityQueue[T]) Peek

func (p *PriorityQueue[T]) Peek() (_ T, _ bool)

func (*PriorityQueue[T]) Pop

func (p *PriorityQueue[T]) Pop() (_ T, _ bool)

func (*PriorityQueue[T]) Push

func (p *PriorityQueue[T]) Push(es ...T)

func (*PriorityQueue[T]) Size

func (p *PriorityQueue[T]) Size() int

func (*PriorityQueue[T]) String

func (p *PriorityQueue[T]) String() string

func (*PriorityQueue[T]) Values

func (p *PriorityQueue[T]) Values() []T

type Queue

type Queue[T any] interface {
	// Push pushes an element into queue
	Push(e ...T)
	// Peek returns an element on the head of queue
	Peek() (T, bool)
	// Pop returns an element on the head of queue, then pop it from queue
	Pop() (T, bool)

	containers.IndexIterable[T]

	containers.Container[T]
}

Queue is the base interface of all queues implementations

Jump to

Keyboard shortcuts

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