klists

package
v0.4.9 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: Apache-2.0 Imports: 3 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SplitKList

func SplitKList[T comparable](l *KList[T], limit int) [][]T

splitKList 将传入的KList类型的切片l按照给定的limit进行拆分,返回拆分后的结果

参数:

l *klists.KList[T] - 待拆分的KList类型的切片
limit int - 拆分后每个子切片的最大长度

返回值:

[]T - 拆分后的结果切片

func ToKSlice

func ToKSlice[T comparable](l *KList[T]) []T

将列表转换为切片

func ToSlice

func ToSlice[T any](l *list.List) []T

将列表转换为切片

func ToSliceIf

func ToSliceIf[T any](l *list.List, callback func(item T) bool) []T

将列表转换为切片

Types

type KElement

type KElement[E comparable] struct {

	// The value stored with this element.
	Value E
	// contains filtered or unexported fields
}

Element is an element of a linked list.

func (*KElement[E]) Next

func (e *KElement[E]) Next() *KElement[E]

Next returns the next list element or nil.

func (*KElement[E]) Prev

func (e *KElement[E]) Prev() *KElement[E]

Prev returns the previous list element or nil.

type KList

type KList[E comparable] struct {
	// contains filtered or unexported fields
}

List represents a doubly linked list. The zero value for List is an empty list ready to use.

func FilterFunc

func FilterFunc[T comparable](l *KList[T], callback func(v T) bool) *KList[T]

func New

func New[E comparable]() *KList[E]

New returns an initialized list.

func (*KList[E]) At

func (l *KList[E]) At(index int) *E

获取指定序号的元素

func (*KList[E]) Back

func (l *KList[E]) Back() *KElement[E]

Back returns the last element of list l or nil if the list is empty.

func (*KList[E]) Clear

func (l *KList[E]) Clear()

func (*KList[E]) FindAllIf

func (l *KList[E]) FindAllIf(callback func(v E) bool) []E

func (*KList[E]) FindIf

func (l *KList[E]) FindIf(callback func(v E) bool) *E

func (*KList[E]) Front

func (l *KList[E]) Front() *KElement[E]

Front returns the first element of list l or nil if the list is empty.

func (*KList[E]) Init

func (l *KList[E]) Init() *KList[E]

Init initializes or clears list l.

func (*KList[E]) InsertAfter

func (l *KList[E]) InsertAfter(v E, mark *KElement[E]) *KElement[E]

InsertAfter inserts a new element e with value v immediately after mark and returns e. If mark is not an element of l, the list is not modified. The mark must not be nil.

func (*KList[E]) InsertBefore

func (l *KList[E]) InsertBefore(v E, mark *KElement[E]) *KElement[E]

InsertBefore inserts a new element e with value v immediately before mark and returns e. If mark is not an element of l, the list is not modified. The mark must not be nil.

func (*KList[E]) Len

func (l *KList[E]) Len() int

Len returns the number of elements of list l. The complexity is O(1).

func (*KList[E]) MoveAfter

func (l *KList[E]) MoveAfter(e, mark *KElement[E])

MoveAfter moves element e to its new position after mark. If e or mark is not an element of l, or e == mark, the list is not modified. The element and mark must not be nil.

func (*KList[E]) MoveBefore

func (l *KList[E]) MoveBefore(e, mark *KElement[E])

MoveBefore moves element e to its new position before mark. If e or mark is not an element of l, or e == mark, the list is not modified. The element and mark must not be nil.

func (*KList[E]) MoveToBack

func (l *KList[E]) MoveToBack(e *KElement[E])

MoveToBack moves element e to the back of list l. If e is not an element of l, the list is not modified. The element must not be nil.

func (*KList[E]) MoveToFront

func (l *KList[E]) MoveToFront(e *KElement[E])

MoveToFront moves element e to the front of list l. If e is not an element of l, the list is not modified. The element must not be nil.

func (*KList[E]) PopAllIf

func (l *KList[E]) PopAllIf(callback func(v E) bool) []E

func (*KList[E]) PopBack

func (l *KList[E]) PopBack() *E

func (*KList[E]) PopFront

func (l *KList[E]) PopFront() *E

func (*KList[E]) PopIf

func (l *KList[E]) PopIf(callback func(v E) bool) *E

func (*KList[E]) PushBack

func (l *KList[E]) PushBack(v E) *KElement[E]

PushBack inserts a new element e with value v at the back of list l and returns e.

func (*KList[E]) PushBackList

func (l *KList[E]) PushBackList(other *KList[E])

PushBackList inserts a copy of another list at the back of list l. The lists l and other may be the same. They must not be nil.

func (*KList[E]) PushBackSlice

func (l *KList[E]) PushBackSlice(v ...E) *KElement[E]

PushBack inserts a new element e with value v at the back of list l and returns e.

func (*KList[E]) PushFront

func (l *KList[E]) PushFront(v E) *KElement[E]

PushFront inserts a new element e with value v at the front of list l and returns e.

func (*KList[E]) PushFrontList

func (l *KList[E]) PushFrontList(other *KList[E])

PushFrontList inserts a copy of another list at the front of list l. The lists l and other may be the same. They must not be nil.

func (*KList[E]) PushFrontSlice

func (l *KList[E]) PushFrontSlice(v ...E) *KElement[E]

func (*KList[E]) Remove

func (l *KList[E]) Remove(e *KElement[E]) E

Remove removes e from l if e is an element of list l. It returns the element value e.Value. The element must not be nil.

func (KList[E]) String

func (l KList[E]) String() string

func (KList[E]) ToJson5

func (l KList[E]) ToJson5(ident string) string

func (KList[E]) ToString

func (l KList[E]) ToString() string

Jump to

Keyboard shortcuts

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