inlist

package
v0.0.0-...-012d1c6 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2021 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package inlist implements an intrusive doubly linked list.

To iterate over a list (where l is a *List):

for e := l.Front(); e != nil; e = e.Next() {
	// do something with e
}

修改了部分接口,以便和标准的一致 只有MoveFrontList和MoveBackList和标准不一样,因为标准是拷贝,这里是移动合并 增加PopFront和PopBack接口

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Value

func Value(i Intrusive) interface{}

Value return value of element

Types

type Element

type Element struct {
	Hook
	Value interface{}
}

Element impl Intrusive

type Hook

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

func (*Hook) List

func (h *Hook) List() *List

func (*Hook) Next

func (h *Hook) Next() Intrusive

func (*Hook) Prev

func (h *Hook) Prev() Intrusive

type Intrusive

type Intrusive interface {
	Prev() Intrusive
	Next() Intrusive
	List() *List
	// contains filtered or unexported methods
}

Intrusive interface of Element

func NewElement

func NewElement(v interface{}) Intrusive

NewElement creates an intrusive Element to store the passed value.

func Next

func Next(e Intrusive) (ret Intrusive)

Next old code,do not need!!!

func Prev

func Prev(e Intrusive) (ret Intrusive)

Prev old code,do not need!!!

type List

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

func New

func New() *List

func (*List) Back

func (l *List) Back() Intrusive

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

func (*List) Front

func (l *List) Front() Intrusive

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

func (*List) Init

func (l *List) Init() *List

func (*List) InsertAfter

func (l *List) InsertAfter(e Intrusive, mark Intrusive) Intrusive

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 (*List) InsertBefore

func (l *List) InsertBefore(e Intrusive, mark Intrusive) Intrusive

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 (*List) Len

func (l *List) Len() int

func (*List) MoveAfter

func (l *List) MoveAfter(e, mark Intrusive)

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 (*List) MoveBackList

func (l *List) MoveBackList(other *List)

MoveBackList moves all elements from other to the end of this list. diff with MoveBackList, because that is copy, here is move

func (*List) MoveBefore

func (l *List) MoveBefore(e, mark Intrusive)

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 (*List) MoveFrontList

func (l *List) MoveFrontList(other *List)

MoveFrontList moves all elements from other to the front of this list. diff with PushFrontList, because that is copy, here is move

func (*List) MoveToBack

func (l *List) MoveToBack(e Intrusive)

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 (*List) MoveToFront

func (l *List) MoveToFront(e Intrusive)

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 (*List) PopBack

func (l *List) PopBack() Intrusive

PopBack remove and return back element

func (*List) PopFront

func (l *List) PopFront() Intrusive

PopFront remove and return front element

func (*List) PushBack

func (l *List) PushBack(e Intrusive) Intrusive

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

func (*List) PushFront

func (l *List) PushFront(e Intrusive) Intrusive

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

func (*List) Remove

func (l *List) Remove(e Intrusive) bool

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.

Jump to

Keyboard shortcuts

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