container

package
v0.2.34 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: LGPL-2.1 Imports: 0 Imported by: 0

Documentation

Overview

Package container 实现了一种特殊的链表,可以在遍历时在任意位置添加或删除元素,递归添加或删除元素时仍然能正常工作,但是需要GC支持,主要用于ec包内部。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Allocator

type Allocator[T any] interface {
	// Alloc 分配链表元素
	Alloc() *Element[T]
}

Allocator 链表内存分配器

func DefaultAllocator

func DefaultAllocator[T any]() Allocator[T]

DefaultAllocator 默认的链表内存分配器

type Element

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

Element 元素

func (*Element[T]) Escape

func (e *Element[T]) Escape()

Escape 从链表中删除

func (*Element[T]) Escaped

func (e *Element[T]) Escaped() bool

Escaped 是否已从链表中删除

func (*Element[T]) Next

func (e *Element[T]) Next() *Element[T]

Next 下一个元素

func (*Element[T]) Prev

func (e *Element[T]) Prev() *Element[T]

Prev 前一个元素

func (*Element[T]) Released

func (e *Element[T]) Released() bool

Released 是否已从链表中释放

type GC

type GC interface {
	// GC GC
	GC()
	// NeedGC 是否需要GC
	NeedGC() bool
}

GC GC接口

type GCCollector

type GCCollector interface {
	// CollectGC 收集GC
	CollectGC(gc GC)
}

GCCollector GC收集器接口

type List

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

List 链表,非线程安全,支持在遍历过程中删除元素

func NewList

func NewList[T any](allocator Allocator[T], gcCollector GCCollector) *List[T]

NewList 创建链表

func (*List[T]) Back

func (l *List[T]) Back() *Element[T]

Back 链表尾部

func (*List[T]) Cap

func (l *List[T]) Cap() int

Cap 链表容量,包含已标记需要GC的元素

func (*List[T]) Front

func (l *List[T]) Front() *Element[T]

Front 链表头部

func (*List[T]) GC

func (l *List[T]) GC()

GC 执行GC

func (*List[T]) GetAllocator

func (l *List[T]) GetAllocator() Allocator[T]

GetAllocator 获取链表内存分配器

func (*List[T]) GetGCCollector

func (l *List[T]) GetGCCollector() GCCollector

GetGCCollector 获取GC收集器

func (*List[T]) Init

func (l *List[T]) Init(allocator Allocator[T], gcCollector GCCollector) *List[T]

Init 初始化

func (*List[T]) InsertAfter

func (l *List[T]) InsertAfter(value T, mark *Element[T]) *Element[T]

InsertAfter 在链表指定位置后插入数据

func (*List[T]) InsertBefore

func (l *List[T]) InsertBefore(value T, mark *Element[T]) *Element[T]

InsertBefore 在链表指定位置前插入数据

func (*List[T]) Len

func (l *List[T]) Len() int

Len 链表长度

func (*List[T]) MoveAfter

func (l *List[T]) MoveAfter(e, mark *Element[T])

MoveAfter 移动元素至链表指定位置后

func (*List[T]) MoveBefore

func (l *List[T]) MoveBefore(e, mark *Element[T])

MoveBefore 移动元素至链表指定位置前

func (*List[T]) MoveToBack

func (l *List[T]) MoveToBack(e *Element[T])

MoveToBack 移动元素至链表尾部

func (*List[T]) MoveToFront

func (l *List[T]) MoveToFront(e *Element[T])

MoveToFront 移动元素至链表头部

func (*List[T]) NeedGC

func (l *List[T]) NeedGC() bool

NeedGC 是否需要GC

func (*List[T]) PushBack

func (l *List[T]) PushBack(value T) *Element[T]

PushBack 在链表尾部插入数据

func (*List[T]) PushBackList

func (l *List[T]) PushBackList(other *List[T])

PushBackList 在链表尾部插入其他链表

func (*List[T]) PushFront

func (l *List[T]) PushFront(value T) *Element[T]

PushFront 在链表头部插入数据

func (*List[T]) PushFrontList

func (l *List[T]) PushFrontList(other *List[T])

PushFrontList 在链表头部插入其他链表

func (*List[T]) Remove

func (l *List[T]) Remove(e *Element[T]) T

Remove 删除元素

func (*List[T]) ReverseTraversal

func (l *List[T]) ReverseTraversal(visitor func(e *Element[T]) bool)

ReverseTraversal 反向遍历元素

func (*List[T]) ReverseTraversalAt

func (l *List[T]) ReverseTraversalAt(visitor func(e *Element[T]) bool, mark *Element[T])

ReverseTraversalAt 从指定位置开始反向遍历元素

func (*List[T]) SetAllocator

func (l *List[T]) SetAllocator(allocator Allocator[T])

SetAllocator 设置链表内存分配器

func (*List[T]) SetGCCollector

func (l *List[T]) SetGCCollector(gcCollector GCCollector)

SetGCCollector 设置GC收集器

func (*List[T]) Traversal

func (l *List[T]) Traversal(visitor func(e *Element[T]) bool)

Traversal 遍历元素

func (*List[T]) TraversalAt

func (l *List[T]) TraversalAt(visitor func(e *Element[T]) bool, mark *Element[T])

TraversalAt 从指定位置开始遍历元素

Jump to

Keyboard shortcuts

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