listparam

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2022 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

package listparam wraps doubly-linked list implemented in go programming langauge standard library, to accept type parameter.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Element

type Element[T any] struct {
	// contains filtered or unexported fields
}

func (*Element[T]) Get

func (e *Element[T]) Get() (v T, ok bool)

Get returns internal Value. If internal Value is non-nil and then returns value and true. Otherwise returns zero of T and false.

func (*Element[T]) Next

func (e *Element[T]) Next() *Element[T]

func (*Element[T]) Prev

func (e *Element[T]) Prev() *Element[T]

func (*Element[T]) Set

func (e *Element[T]) Set(v T)

Set is equivalent to `element.Value = v`

func (*Element[T]) Unwrap

func (e *Element[T]) Unwrap() *list.Element

Unwrap returns internal *`container/list`.Element. Setting non-T value may cause runtime panic in succeeding Get call.

type List

type List[T any] struct {
	// contains filtered or unexported fields
}

List[T] is `container/list` wrapper that is safe to use with type T.

It holds *`container/list`.List and map[*list.Element]*Element[T]. This map maps *Element[T] to *list.Element so that you can identify elements by simple comparision like eleA == eleB.

List[T] tries best to be consistent with `container/list`. The zero value of List[T] is a valid empty list (which will be lazily initialized).

func New

func New[T any]() *List[T]

func (*List[T]) Back

func (l *List[T]) Back() *Element[T]

func (*List[T]) Front

func (l *List[T]) Front() *Element[T]

func (*List[T]) Init

func (l *List[T]) Init() *List[T]

func (*List[T]) InsertAfter

func (l *List[T]) InsertAfter(v T, mark *Element[T]) *Element[T]

func (*List[T]) InsertBefore

func (l *List[T]) InsertBefore(v T, mark *Element[T]) *Element[T]

func (*List[T]) Len

func (l *List[T]) Len() int

func (*List[T]) MoveAfter

func (l *List[T]) MoveAfter(e, mark *Element[T])

func (*List[T]) MoveBefore

func (l *List[T]) MoveBefore(e, mark *Element[T])

func (*List[T]) MoveToBack

func (l *List[T]) MoveToBack(e *Element[T])

func (*List[T]) MoveToFront

func (l *List[T]) MoveToFront(e *Element[T])

func (*List[T]) PushBack

func (l *List[T]) PushBack(v T) *Element[T]

PushBack inserts v at end of the list and returns inserted element.

func (*List[T]) PushBackList

func (l *List[T]) PushBackList(other *List[T])

PushBackList copies values of other and inserts them into back of l.

Both l and other must not be nil.

func (*List[T]) PushFront

func (l *List[T]) PushFront(v T) *Element[T]

PushFront inserts v at front of the list and returns inserted element.

func (*List[T]) PushFrontList

func (l *List[T]) PushFrontList(other *List[T])

PushFrontList copies values of other and inserts them into front of l.

Both l and other must not be nil.

func (*List[T]) Remove

func (l *List[T]) Remove(e *Element[T]) (v T, hadValue bool)

Remove removes element from list l and returns value of e. hadValue is false when e.Value is nil.

e must not be nil.

Jump to

Keyboard shortcuts

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