container

package
v0.0.0-...-2f8f7b3 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

此文件实现了线程安全一个队列和线程安全一个双链表

Index

Constants

View Source
const CQUEUE_SIZE = 5

Variables

This section is empty.

Functions

This section is empty.

Types

type CirCleQueue

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

SqQueue 结构体定义

func NewCircleQueue

func NewCircleQueue() *CirCleQueue

New 新建空队列

func (*CirCleQueue) Dequeue

func (c *CirCleQueue) Dequeue() (e interface{}, err error)

Dequeue 出队

func (*CirCleQueue) Enqueue

func (c *CirCleQueue) Enqueue(e interface{}) error

Enqueue 入队

func (*CirCleQueue) ForEach

func (c *CirCleQueue) ForEach(f func(data interface{}) bool)

func (*CirCleQueue) Len

func (c *CirCleQueue) Len() interface{}

Length 队列长度

func (*CirCleQueue) Snapshot

func (c *CirCleQueue) Snapshot() []interface{}

type Deque

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

func NewCappedDeque

func NewCappedDeque(capacity int) *Deque

newCappedRequest创建具有指定容量限制的Deque。

-1 表示不限制容量

func NewDeque

func NewDeque() *Deque

Deque使用双向链表实现,每个操作的时间复杂度为O(1)。 并且是同步&&并发安全的

func (*Deque) Back

func (s *Deque) Back() interface{}

Back(): 时间复杂度O(1), 获取队尾元素

func (*Deque) Capacity

func (s *Deque) Capacity() int

Capacity(): 时间复杂度O(1), 获取队列容量, -1表示不限制容量

func (*Deque) Dump

func (q *Deque) Dump()

func (*Deque) Empty

func (s *Deque) Empty() bool

Empty(): 时间复杂度O(1),检查队列是否为空

func (*Deque) Front

func (s *Deque) Front() interface{}

Front(): 时间复杂度O(1), 获取队首元素

func (*Deque) Full

func (s *Deque) Full() bool

Empty(): 时间复杂度O(1),检查队列是否满了

func (*Deque) PopFront

func (s *Deque) PopFront() interface{}

PopFront: 时间复杂度O(1), 移除队首元素 返回移除的元素。 如果当前队列为空,则返回nil

func (*Deque) PushBack

func (s *Deque) PushBack(item interface{}) bool

PushBack: 在Deque尾部以O(1)时间复杂度插入元素, 如果成功,则返回true;如果Deque已满容量,则返回false。

func (*Deque) PushFront

func (s *Deque) PushFront(item interface{}) bool

PushFront: 在Deque头部以O(1)时间复杂度插入元素, 如果成功,则返回true;如果Deque已满容量,则返回false。

func (*Deque) Size

func (s *Deque) Size() int

Size(): 时间复杂度O(1), 获取队列长度

type LinkList struct {
	Head *ListNode
	Tail *ListNode

	sync.Mutex
	// contains filtered or unexported fields
}
func NewLinkList() *LinkList

func (*LinkList) Clear

func (l *LinkList) Clear()

func (*LinkList) ForEach

func (l *LinkList) ForEach(f func(node *ListNode) bool)

func (*LinkList) GetAfter

func (l *LinkList) GetAfter(Data interface{}) *ListNode

获取某个元素的后一个节点

func (*LinkList) GetBefore

func (l *LinkList) GetBefore(Data interface{}) *ListNode

获取某个元素的前一个节点

func (*LinkList) IsEmpty

func (l *LinkList) IsEmpty() bool

func (*LinkList) Len

func (l *LinkList) Len() int

func (*LinkList) Pop

func (l *LinkList) Pop(Data interface{})

删除某个元素

func (*LinkList) PopFront

func (l *LinkList) PopFront() interface{}

删除头部

func (*LinkList) PopTail

func (l *LinkList) PopTail() interface{}

删除尾部

func (*LinkList) PushAfter

func (l *LinkList) PushAfter(node *ListNode, inData interface{})

Data1后插入Data2

func (*LinkList) PushBefore

func (l *LinkList) PushBefore(node *ListNode, inData interface{})

Data1前插入Data2

func (*LinkList) PushFront

func (l *LinkList) PushFront(Data interface{})

头部插入

func (*LinkList) PushTail

func (l *LinkList) PushTail(Data interface{})

尾部插入

func (*LinkList) Snapshot

func (l *LinkList) Snapshot() []*ListNode

func (*LinkList) String

func (l *LinkList) String() string

type ListNode

type ListNode struct {
	Data interface{}
	Prev *ListNode
	Next *ListNode
}

type Queue

type Queue struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewQueue

func NewQueue() *Queue

func (*Queue) Clear

func (q *Queue) Clear()

func (*Queue) ForEach

func (q *Queue) ForEach(f func(node *ListNode) bool)

func (*Queue) IsEmpty

func (q *Queue) IsEmpty() bool

func (*Queue) Len

func (q *Queue) Len() int

func (*Queue) PopFront

func (q *Queue) PopFront() interface{}

删除头部

func (*Queue) PopTail

func (q *Queue) PopTail() interface{}

删除尾部

func (*Queue) PushFront

func (q *Queue) PushFront(Data interface{})

头部插入

func (*Queue) PushTail

func (q *Queue) PushTail(Data interface{})

尾部插入

func (*Queue) Snapshot

func (q *Queue) Snapshot() []*ListNode

func (*Queue) String

func (q *Queue) String() string

Jump to

Keyboard shortcuts

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