list

package
v2.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type List

type List struct {
	// contains filtered or unexported fields
}

List 结构体代表一个双向链表,它有一个头节点和一个尾节点,以及一个记录链表长度的字段。 The List struct represents a doubly linked list. It has a head node, a tail node, and a field to record the length of the list.

func New

func New() *List

New 函数创建并返回一个新的 List 实例。 The New function creates and returns a new instance of List.

func (*List) Back

func (l *List) Back() *Node

Back 方法返回链表的尾节点。 The Back method returns the tail node of the list.

func (*List) Cleanup

func (l *List) Cleanup()

Cleanup 方法清理链表,移除所有节点并重置链表的状态。 The Cleanup method cleans up the list, removes all nodes and resets the state of the list.

func (*List) Front

func (l *List) Front() *Node

Front 方法返回链表的头节点。 The Front method returns the head node of the list.

func (*List) InsertAfter

func (l *List) InsertAfter(n, mark *Node)

InsertAfter 方法将节点 n 插入到节点 mark 的后面。 The InsertAfter method inserts node n after node mark.

func (*List) InsertBefore

func (l *List) InsertBefore(n, mark *Node)

InsertBefore 方法将节点 n 插入到节点 mark 的前面。 The InsertBefore method inserts node n before node mark.

func (*List) Len

func (l *List) Len() int64

Len 方法返回链表的长度。 The Len method returns the length of the list.

func (*List) MoveToBack

func (l *List) MoveToBack(n *Node)

MoveToBack 方法将节点 n 移动到链表的尾部。 The MoveToBack method moves node n to the end of the list.

func (*List) MoveToFront

func (l *List) MoveToFront(n *Node)

MoveToFront 方法将节点 n 移动到链表的头部。 The MoveToFront method moves node n to the front of the list.

func (*List) PopBack

func (l *List) PopBack() *Node

PopBack 方法从链表的尾部移除一个节点并返回它。 The PopBack method removes a node from the end of the list and returns it.

func (*List) PopFront

func (l *List) PopFront() *Node

PopFront 方法从链表的头部移除一个节点并返回它。 The PopFront method removes a node from the beginning of the list and returns it.

func (*List) PushBack

func (l *List) PushBack(n *Node)

PushBack 方法将一个节点添加到链表的尾部。 The PushBack method adds a node to the end of the list.

func (*List) PushFront

func (l *List) PushFront(n *Node)

PushFront 方法将一个节点添加到链表的头部。 The PushFront method adds a node to the beginning of the list.

func (*List) Range

func (l *List) Range(fn func(n *Node) bool)

Range 方法遍历链表,对每个节点执行 fn 函数,如果 fn 返回 false,就停止遍历。 The Range method traverses the list, performs the fn function on each node, and stops traversing if fn returns false.

func (*List) Remove

func (l *List) Remove(n *Node)

Remove 方法从链表中移除节点 n。 The Remove method removes node n from the list.

func (*List) Slice

func (l *List) Slice() []interface{}

Slice 方法将链表转换为一个切片,切片中的元素顺序和链表中的节点顺序一致。 The Slice method converts the list to a slice, the order of the elements in the slice is consistent with the order of the nodes in the list.

func (*List) Swap

func (l *List) Swap(n, mark *Node)

Swap 方法交换链表中的两个节点 n 和 mark 的位置。 The Swap method swaps the positions of two nodes n and mark in the list.

type Node

type Node struct {
	// Value 是存储在节点中的值,它的类型是 interface{},所以可以是任何类型。
	// Value is the value stored in the node. Its type is interface{}, so it can be of any type.
	Value interface{}

	// Priority 是节点的优先级,类型为 int64。
	// Priority is the priority of the node. Its type is int64.
	Priority int64

	// Next 是指向下一个节点的指针。
	// Next is a pointer to the next node.
	// Prev 是指向前一个节点的指针。
	// Prev is a pointer to the previous node.
	Next, Prev *Node
	// contains filtered or unexported fields
}

Node 结构体代表一个节点,它可以存储任何类型的值,有一个优先级,以及指向前一个和后一个节点的指针。 Node struct represents a node that can hold a value of any type, has a priority, and pointers to the next and previous nodes.

func NewNode

func NewNode() *Node

NewNode 函数创建并返回一个新的 Node 实例。 The NewNode function creates and returns a new instance of Node.

func (*Node) Reset

func (n *Node) Reset()

Reset 方法重置节点的所有字段,将它们设置为零值。 The Reset method resets all the fields of the node, setting them to their zero values.

type NodePool

type NodePool struct {
	// contains filtered or unexported fields
}

NodePool 结构体是一个节点池,它使用 sync.Pool 来存储和复用 Node 实例。 The NodePool struct is a pool of nodes, it uses sync.Pool to store and reuse Node instances.

func NewNodePool

func NewNodePool() *NodePool

NewNodePool 函数创建并返回一个新的 NodePool 实例。 The NewNodePool function creates and returns a new instance of NodePool.

func (*NodePool) Get

func (p *NodePool) Get() *Node

Get 方法从 NodePool 中获取一个 Node 实例。 The Get method retrieves a Node instance from the NodePool.

func (*NodePool) Put

func (p *NodePool) Put(n *Node)

Put 方法将一个 Node 实例放回到 NodePool 中。 The Put method puts a Node instance back into the NodePool.

Jump to

Keyboard shortcuts

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