Documentation ¶
Index ¶
- type List
- func (l *List) Back() *Node
- func (l *List) Cleanup()
- func (l *List) Front() *Node
- func (l *List) InsertAfter(n, mark *Node)
- func (l *List) InsertBefore(n, mark *Node)
- func (l *List) Len() int64
- func (l *List) MoveToBack(n *Node)
- func (l *List) MoveToFront(n *Node)
- func (l *List) PopBack() *Node
- func (l *List) PopFront() *Node
- func (l *List) PushBack(n *Node)
- func (l *List) PushFront(n *Node)
- func (l *List) Range(fn func(n *Node) bool)
- func (l *List) Remove(n *Node)
- func (l *List) Slice() []interface{}
- func (l *List) Swap(n, mark *Node)
- type Node
- type NodePool
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) 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 { // 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.
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.