list

package
v0.10.4 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Element

type Element struct {
	Sentinel
	Value interface{}
}

Element allow one to use a list with a generic element.

func NewElement

func NewElement(v interface{}) *Element

func SliceOfElements

func SliceOfElements(vals ...interface{}) []*Element

func (Element) String

func (e Element) String() string

type Elementer

type Elementer interface {
	// Prev returns the previous list element or nil.
	Prev() Elementer
	// Next returns the next list element or nil
	Next() Elementer
	// SetNext will set this list element next element to the provided element, and return the element or nil that was point to before.
	// SetNext does not call SetPrev.
	SetNext(n Elementer) Elementer
	// SetPrev will set this list element's prev element to the provided element, if
	// SetPrev does not call SetNext.
	SetPrev(n Elementer) Elementer

	// List is the list this Node belongs to.
	List() *List
	// SetList set the list this node should belong to; should return the old list or nil if it does not belong to a list.
	SetList(l *List) *List
}

type List

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

func New

func New() *List

New returns an initialized list.

func (*List) Back

func (l *List) Back() Elementer

Back returns the last element of list l or nil.

func (*List) FindElementBackward

func (l *List) FindElementBackward(start, end Elementer, finder func(e Elementer) (didFind bool)) (found Elementer)

FindElementBackward will start at the start elemente working it's way backwards to the end element (or back to the sentinel element of the list if nil is provided) calling the match function. It returns the element that was found or nil if it did not find any element. Both start and end have to be in the list otherwise nil is retured.

func (*List) FindElementForward

func (l *List) FindElementForward(start, end Elementer, finder func(e Elementer) (didFind bool)) (found Elementer)

FindElementForward will start at the start element working it's way to the end element (or back to the sentinel element of the list if nil is provided) calling the match function. It return that element or nil if it did not find a point. Both start and end have to be in the list otherwise the function will return nil.

func (*List) Front

func (l *List) Front() Elementer

Front returns the first element of list l or nil.

func (*List) Init

func (l *List) Init() *List

Init initializes or clears list l.

func (*List) InsertAfter

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

InsertAfter inserts a new element e immediately after the mark and returns e. If mark is not an element of l, the list is not modified.

func (*List) InsertBefore

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

InsertBefore inserts a new element e immediately before mark and returns e. If mark is not an element of , the list is not modified.

func (*List) IsSentinel

func (l *List) IsSentinel(e Elementer) bool

IsSentinel returns weather or not the provided element is the sentinel element of the list.

func (*List) Len

func (l *List) Len() int

Len returns the number of elements of list l

func (*List) MoveAfter

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

MoveAfter move 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.

func (*List) MoveBefore

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

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 modifed

func (*List) MoveToBack

func (l *List) MoveToBack(e Elementer)

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

func (*List) MoveToFront

func (l *List) MoveToFront(e Elementer)

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

func (*List) PushBack

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

PushBack inserts a new element e to the back of the list l and returns e.

func (*List) PushFront

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

PushFront inserts a new element e to the front of the list l and returns e.

func (*List) Remove

func (l *List) Remove(e Elementer) Elementer

func (*List) Replace

func (l *List) Replace(e, mark Elementer) Elementer

Replace replaces the mark with the new element e, and returns the mark. If mark is not an element of l, the list is not modified and nil is returned.

type Sentinel

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

func (*Sentinel) List

func (s *Sentinel) List() *List

func (*Sentinel) Next

func (s *Sentinel) Next() Elementer

func (*Sentinel) Prev

func (s *Sentinel) Prev() Elementer

func (*Sentinel) SetList

func (s *Sentinel) SetList(l *List) (oldList *List)

func (*Sentinel) SetNext

func (s *Sentinel) SetNext(e Elementer) (oldElement Elementer)

func (*Sentinel) SetPrev

func (s *Sentinel) SetPrev(e Elementer) (oldElement Elementer)

func (*Sentinel) String

func (s *Sentinel) String() string

Directories

Path Synopsis
point

Jump to

Keyboard shortcuts

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