gf: github.com/johng-cn/gf/g/container/glist Index | Examples | Files

package glist

import "github.com/johng-cn/gf/g/container/glist"

Package glist provides a concurrent-safe/unsafe doubly linked list.

Code:

n := 10
l := glist.New()
for i := 0; i < n; i++ {
    l.PushBack(i)
}
fmt.Println(l.Len())
fmt.Println(l.FrontAll())
fmt.Println(l.BackAll())
for i := 0; i < n; i++ {
    fmt.Print(l.PopFront())
}
l.Clear()
fmt.Println()
fmt.Println(l.Len())

Output:

10
[0 1 2 3 4 5 6 7 8 9]
[9 8 7 6 5 4 3 2 1 0]
0123456789
0

Index

Examples

Package Files

glist.go

type Element Uses

type Element = list.Element

type List Uses

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

func New Uses

func New(unsafe ...bool) *List

New creates and returns a new empty doubly linked list.

func (*List) Back Uses

func (l *List) Back() (e *Element)

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

func (*List) BackAll Uses

func (l *List) BackAll() (values []interface{})

BackAll copies and returns values of all elements from back of <l> as slice.

func (*List) BackValue Uses

func (l *List) BackValue() (value interface{})

BackValue returns value of the last element of <l> or nil if the list is empty.

func (*List) Clear Uses

func (l *List) Clear()

See RemoveAll().

func (*List) Front Uses

func (l *List) Front() (e *Element)

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

func (*List) FrontAll Uses

func (l *List) FrontAll() (values []interface{})

FrontAll copies and returns values of all elements from front of <l> as slice.

func (*List) FrontValue Uses

func (l *List) FrontValue() (value interface{})

FrontValue returns value of the first element of <l> or nil if the list is empty.

func (*List) InsertAfter Uses

func (l *List) InsertAfter(v interface{}, p *Element) (e *Element)

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

func (*List) InsertBefore Uses

func (l *List) InsertBefore(v interface{}, p *Element) (e *Element)

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

func (*List) Iterator Uses

func (l *List) Iterator(f func(e *Element) bool)

Iterator is alias of IteratorAsc.

func (*List) IteratorAsc Uses

func (l *List) IteratorAsc(f func(e *Element) bool)

IteratorAsc iterates the list in ascending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.

func (*List) IteratorDesc Uses

func (l *List) IteratorDesc(f func(e *Element) bool)

IteratorDesc iterates the list in descending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.

func (*List) Len Uses

func (l *List) Len() (length int)

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

func (*List) LockFunc Uses

func (l *List) LockFunc(f func(list *list.List))

LockFunc locks writing with given callback function <f> within RWMutex.Lock.

func (*List) MoveAfter Uses

func (l *List) MoveAfter(e, p *Element)

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

func (*List) MoveBefore Uses

func (l *List) MoveBefore(e, p *Element)

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

func (*List) MoveToBack Uses

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

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

func (l *List) PopBack() (value interface{})

PopBack removes the element from back of <l> and returns the value of the element.

func (*List) PopBackAll Uses

func (l *List) PopBackAll() []interface{}

PopBackAll removes all elements from back of <l> and returns values of the removed elements as slice.

func (*List) PopBacks Uses

func (l *List) PopBacks(max int) (values []interface{})

PopBacks removes <max> elements from back of <l> and returns values of the removed elements as slice.

func (*List) PopFront Uses

func (l *List) PopFront() (value interface{})

PopFront removes the element from front of <l> and returns the value of the element.

func (*List) PopFrontAll Uses

func (l *List) PopFrontAll() []interface{}

PopFrontAll removes all elements from front of <l> and returns values of the removed elements as slice.

func (*List) PopFronts Uses

func (l *List) PopFronts(max int) (values []interface{})

PopFronts removes <max> elements from front of <l> and returns values of the removed elements as slice.

func (*List) PushBack Uses

func (l *List) PushBack(v interface{}) (e *Element)

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

func (*List) PushBackList Uses

func (l *List) PushBackList(other *List)

PushBackList inserts a copy of an other list at the back of list <l>. The lists <l> and <other> may be the same, but they must not be nil.

func (*List) PushBacks Uses

func (l *List) PushBacks(values []interface{})

PushBacks inserts multiple new elements with values <values> at the back of list <l>.

func (*List) PushFront Uses

func (l *List) PushFront(v interface{}) (e *Element)

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

func (*List) PushFrontList Uses

func (l *List) PushFrontList(other *List)

PushFrontList inserts a copy of an other list at the front of list <l>. The lists <l> and <other> may be the same, but they must not be nil.

func (*List) PushFronts Uses

func (l *List) PushFronts(values []interface{})

PushFronts inserts multiple new elements with values <values> at the front of list <l>.

func (*List) RLockFunc Uses

func (l *List) RLockFunc(f func(list *list.List))

RLockFunc locks reading with given callback function <f> within RWMutex.RLock.

func (*List) Remove Uses

func (l *List) Remove(e *Element) (value 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.

func (*List) RemoveAll Uses

func (l *List) RemoveAll()

RemoveAll removes all elements from list <l>.

func (*List) Removes Uses

func (l *List) Removes(es []*Element)

Removes removes multiple elements <es> from <l> if <es> are elements of list <l>.

func (*List) Size Uses

func (l *List) Size() int

Size is alias of Len.

Package glist imports 2 packages (graph). Updated 2019-06-19. Refresh now. Tools for package owners.