Documentation ¶
Index ¶
- Constants
- type List
- func (l *List) Back() *Node
- func (l *List) Cleanup()
- func (l *List) Front() *Node
- func (l *List) InsertAfter(node, mark *Node)
- func (l *List) InsertBefore(node, mark *Node)
- func (l *List) Len() int64
- func (l *List) MoveToBack(node *Node)
- func (l *List) MoveToFront(node *Node)
- func (l *List) PopBack() *Node
- func (l *List) PopFront() *Node
- func (l *List) PushBack(node *Node)
- func (l *List) PushFront(node *Node)
- func (l *List) Range(fn func(node *Node) bool)
- func (l *List) Remove(node *Node)
- func (l *List) Slice() []interface{}
- func (l *List) Swap(node, mark *Node)
- type Node
- type NodePool
Constants ¶
const ( // RED 表示红色 // RED represents red RED = 0 // BLACK 表示黑色 // BLACK represents black BLACK = 1 )
定义两个常量,表示节点的颜色 Define two constants to represent the color of the node
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) 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) InsertAfter ¶
InsertAfter 方法将节点 n 插入到节点 mark 的后面。 The InsertAfter method inserts node n after node mark.
func (*List) InsertBefore ¶
InsertBefore 方法将节点 n 插入到节点 mark 的前面。 The InsertBefore method inserts node n before node mark.
func (*List) MoveToBack ¶
MoveToBack 方法将节点 n 移动到链表的尾部。 The MoveToBack method moves node n to the end of the list.
func (*List) MoveToFront ¶
MoveToFront 方法将节点 n 移动到链表的头部。 The MoveToFront method moves node n to the front of the list.
func (*List) PopBack ¶
PopBack 方法从链表的尾部移除一个节点并返回它。 The PopBack method removes a node from the end of the list and returns it.
func (*List) PopFront ¶
PopFront 方法从链表的头部移除一个节点并返回它。 The PopFront method removes a node from the beginning of the list and returns it.
func (*List) PushBack ¶
PushBack 方法将一个节点添加到链表的尾部。 The PushBack method adds a node to the end of the list.
func (*List) PushFront ¶
PushFront 方法将一个节点添加到链表的头部。 The PushFront method adds a node to the beginning of the list.
func (*List) Range ¶
Range 方法遍历链表,对每个节点执行 fn 函数,如果 fn 返回 false,就停止遍历。 The Range method traverses the list, performs the fn function on each node, and stops traversing if fn returns false.
type Node ¶
type Node struct { // Priority 是节点的优先级 // Priority is the Priority of the node Priority int64 // Color 是节点的颜色,可以是 RED 或 BLACK // Color is the Color of the node, can be RED or BLACK Color int64 // Left 是节点的左子节点 // Left is the Left child of the node Left *Node // Right 是节点的右子节点 // Right is the Right child of the node Right *Node // Parent 是节点的父节点 // Parent is the Parent of the node Parent *Node // Value 是节点存储的值 // Value is the value stored in the node Value interface{} // 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.
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.