list

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MyCallerFileLine

func MyCallerFileLine() string

MyCallerFileLine returns the FileLine of the caller of the function that called it :)

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 {
	// 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

	// 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
}

Elementer is a node in the list. Manages it's next and previous elements.

type List

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

List contains pointers to the start element and the end element of a list.

func New

func New() *List

New returns an initialized list.

func (*List) Back

func (l *List) Back() Elementer

Back returns the last element of the list l or nil.

func (*List) Clear

func (l *List) Clear()

Clear will remove all the items from the list.

func (*List) FindElementsBetween

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

ForElementsBetween 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) ForEach

func (l *List) ForEach(fn func(e Elementer) bool)

ForEach call fn for each element in the list. Return false stops the iteration.

func (*List) ForEachIdx

func (l *List) ForEachIdx(fn func(idx int, e Elementer) bool)

ForEach call fn for each element in the list. Return false stops the iteration.

func (*List) Front

func (l *List) Front() Elementer

Front returns the first element of list l or nil.

func (*List) GetBefore

func (l *List) GetBefore(m Elementer) Elementer

GetBefore will return the element before this element. If the element is not in the list, it will return nil.

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) IsInList

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

IsInList will check if the element is in the list.

func (*List) Len

func (l *List) Len() int

Len returns the number of elements of list l

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) Range

func (l *List) Range(ctx context.Context) <-chan Elementer

Range will start up a go routine, and send every element in the list at the time the call is made. It will make a copy of the elements in the list, so that changes in the list does not effect order. The channel is closed and the go routine exists when the list is exhausted or the ctx is done.

func (*List) Remove

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

Remove will remove the element from this list if exists in the list.

type Sentinel

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

Sentinel Provides the a very basic struct that fulfills the Elementer interface. It is meant to be embedded into other structs that want to fulfill the interface.

func (*Sentinel) List

func (s *Sentinel) List() *List

Returns the list.

func (*Sentinel) Next

func (s *Sentinel) Next() Elementer

Returns the next Element in the list.

func (*Sentinel) SetList

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

Set's the list.

func (*Sentinel) SetNext

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

Sets the next element in the list.

Directories

Path Synopsis
point

Jump to

Keyboard shortcuts

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