queue

package
v1.2.89 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2023 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Example
package main

import (
	"fmt"

	"github.com/searKing/golang/go/exp/container/queue"
)

func main() {
	// Create a new list and put some numbers in it.
	l := queue.New[int]()
	l.PushBack(1)
	l.PushBack(2)
	l.PushBack(3)
	l.PushBack(4)

	l2 := queue.New[int]()
	l2.PushBack(5)
	l2.PushBack(6)
	l2.PushBack(7)
	l2.PushBack(8)

	l.PushBackQueue(l2)

	l2.TrimFrontFunc(func(e int) bool {
		return e%2 == 1
	})
	// Iterate through list and print its contents.
	l.Do(func(e int) {
		fmt.Println(e)
	})
	l2.Do(func(e int) {
		fmt.Println(e)
	})

}
Output:

1
2
3
4
5
6
7
8
6
7
8

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

type Queue[E any] struct {
	// contains filtered or unexported fields
}

A Queue is a queue of FIFO, not a deque.

func New

func New[E any]() *Queue[E]

New returns an initialized list.

func (*Queue[E]) Do

func (q *Queue[E]) Do(f func(E))

Do calls function f on each element of the queue without removing it, in forward order. The behavior of Do is undefined if f changes *q.

func (*Queue[E]) Front

func (q *Queue[E]) Front() E

Front returns the item at the front of the queue without removing it.

func (*Queue[E]) Len

func (q *Queue[E]) Len() int

Len returns the number of items in the queue.

func (*Queue[E]) Next

func (q *Queue[E]) Next() bool

Next reports whether there are more iterations to execute. Every call to PopFront, even the first one, must be preceded by a call to Next.

func (*Queue[E]) PopFront

func (q *Queue[E]) PopFront() E

PopFront removes and returns the item at the front of the queue.

func (*Queue[E]) PushBack

func (q *Queue[E]) PushBack(w E)

PushBack adds w to the back of the queue.

func (*Queue[E]) PushBackQueue

func (q *Queue[E]) PushBackQueue(other *Queue[E])

PushBackQueue inserts a copy of another queue at the back of queue l. The queues l and other may be the same. They must not be nil.

func (*Queue[E]) ShrinkToFit

func (q *Queue[E]) ShrinkToFit()

ShrinkToFit requests the removal of unused capacity.

func (*Queue[E]) TrimFrontFunc

func (q *Queue[E]) TrimFrontFunc(f func(e E) bool) (cleaned bool)

TrimFrontFunc pops all leading elem that satisfying f(c) from the head of the queue, reporting whether any were popped.

Jump to

Keyboard shortcuts

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