queue

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2020 License: GPL-3.0 Imports: 2 Imported by: 1

README

queue

queue 提供了一些 常用的 隊列

IQueue 定義了 隊列的一般行為

// IQueue 隊列 定義
type IQueue interface {
	// PushBack 壓入 隊列 尾 失敗 通常返回 ErrQueueOverflow
	PushBack(val interface{}) (e error)
	// PushFront 壓入 隊列 頭 失敗 通常返回 ErrQueueOverflow
	PushFront(val interface{}) (e error)

	// PopBack 從 隊列 尾 出棧 如果為空 返回 nil,ErrQueueEmpty
	PopBack() (val interface{}, e error)
	// PopFront 從 隊列 頭 出棧 如果為空 返回 nil,ErrQueueEmpty
	PopFront() (val interface{}, e error)

	// Cap 返回 隊列 容量
	Cap() int
	// Len 返回 隊列 大小
	Len() int

	// Reset 重置 隊列
	Reset()
}

NewStatic

NewStatic 用數組實現了一個 容量固定的 隊列

func NewStatic(capacity int) (q IQueue, e error) 
package main

import (
	"gitlab.com/king011/king-go/container/queue"
	"log"
)

func main() {
	q, e := queue.NewStatic(3)
	if e != nil {
		log.Fatalln(e)
	}
	q.PushBack(2)
	q.PushBack(3)
	q.PushFront(1)

	for q.Len() != 0 {
		log.Println(q.PopFront())
	}
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrQueueCap = errors.New("queue capacity must large than 0")

ErrQueueCap 初始化 容量太小

View Source
var ErrQueueEmpty = errors.New("queue empty")

ErrQueueEmpty .

View Source
var ErrQueueOverflow = errors.New("queue capacity overflow")

ErrQueueOverflow 容量容量已慢

Functions

This section is empty.

Types

type IQueue

type IQueue interface {
	// PushBack 壓入 隊列 尾 失敗 通常返回 ErrQueueOverflow
	PushBack(val interface{}) (e error)
	// PushFront 壓入 隊列 頭 失敗 通常返回 ErrQueueOverflow
	PushFront(val interface{}) (e error)

	// PopBack 從 隊列 尾 出棧 如果為空 返回 nil,ErrQueueEmpty
	PopBack() (val interface{}, e error)
	// PopFront 從 隊列 頭 出棧 如果為空 返回 nil,ErrQueueEmpty
	PopFront() (val interface{}, e error)

	// Back 返回 隊列 尾 如果為空 返回 nil,ErrQueueEmpty
	Back() (val interface{}, e error)
	// Front 返回 隊列 頭 如果為空 返回 nil,ErrQueueEmpty
	Front() (val interface{}, e error)

	// Cap 返回 隊列 容量
	Cap() int
	// Len 返回 隊列 大小
	Len() int

	// Reset 重置 隊列
	Reset()

	// 遍歷 隊列
	Each(func(val interface{}))
	// 返回隊列是否爲空
	IsEmpty() bool
	// 返回隊列是否已滿
	IsFill() bool
}

IQueue 隊列 定義

func NewStatic

func NewStatic(capacity int) (q IQueue, e error)

NewStatic 返回一個 容量固定的 隊列

func NewStepQueue

func NewStepQueue(step int, cache int) (q IQueue, e error)

NewStepQueue 返回一個 按照 指定 步長增長的 隊列

Jump to

Keyboard shortcuts

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