glinklist

package
v0.0.0-...-3e416e1 Latest Latest
Warning

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

Go to latest
Published: May 19, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package glinklist implements a doubly linked list.

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

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Element

type Element struct {

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

Element is an element of a linked list.

func (*Element) Next

func (e *Element) Next() *Element

Next returns the next list element or nil.

func (*Element) Prev

func (e *Element) Prev() *Element

Prev returns the previous list element or nil.

type LinkList struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

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

func New

func New() *LinkList

New returns an initialized list.

func (*LinkList) Back

func (l *LinkList) Back() *Element

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

func (*LinkList) Clone

func (l *LinkList) Clone() *LinkList

Clone creates a copy of current list.

func (*LinkList) Front

func (l *LinkList) Front() *Element

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

func (*LinkList) IndexOf

func (l *LinkList) IndexOf(v interface{}) int

IndexOf returns the value first occurs index in the linklist, index starts with 0. if not found return -1.

func (*LinkList) Init

func (l *LinkList) Init() *LinkList

Init initializes or clears list l.

func (*LinkList) InsertAfter

func (l *LinkList) InsertAfter(v interface{}, mark *Element) *Element

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

func (l *LinkList) InsertBefore(v interface{}, mark *Element) *Element

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

func (l *LinkList) Len() int64

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

func (*LinkList) MoveAfter

func (l *LinkList) MoveAfter(e, mark *Element)

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 (*LinkList) MoveBefore

func (l *LinkList) MoveBefore(e, mark *Element)

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 (*LinkList) MoveToBack

func (l *LinkList) MoveToBack(e *Element)

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

func (l *LinkList) MoveToFront(e *Element)

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 (*LinkList) PushBack

func (l *LinkList) PushBack(v interface{}) *Element

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

func (*LinkList) PushBackList

func (l *LinkList) PushBackList(other *LinkList)

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

func (*LinkList) PushFront

func (l *LinkList) PushFront(v interface{}) *Element

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

func (*LinkList) PushFrontList

func (l *LinkList) PushFrontList(other *LinkList)

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

func (*LinkList) Range

func (l *LinkList) Range(f func(v interface{}) bool)

Range calls f sequentially for each key and value present in the linklist. If f returns false, range stops the iteration. Don't modify the map during the Range call, that will cause deadlock.

func (*LinkList) Remove

func (l *LinkList) Remove(e *Element) interface{}

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