doublelinkedlist

package
v0.0.0-...-2a10efc Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EnumerableWithIndex

type EnumerableWithIndex[T comparable] interface {
	// Filter returns a new container containing all elements for which the given function returns a true value.
	Filter(func(index int, value T) bool) *List[T]

	containers.EnumerableWithIndex[T]
}

type Iterator

type Iterator[T comparable] struct {
	// contains filtered or unexported fields
}

Iterator represents a forward iterator of a DoubleLinkedList.

func (*Iterator[T]) Begin

func (it *Iterator[T]) Begin()

Begin resets the iterator to its initial state.

func (*Iterator[T]) End

func (it *Iterator[T]) End()

End moves the iterator past the last element in the list.

func (*Iterator[T]) First

func (it *Iterator[T]) First() bool

First moves the iterator to the first element and returns true if there was a first element in the iteration.

func (*Iterator[T]) Index

func (it *Iterator[T]) Index() int

Index returns the current element's index.

func (*Iterator[T]) Last

func (it *Iterator[T]) Last() bool

Last moves the iterator to the last element and returns true if there was a last element in the iteration.

func (*Iterator[T]) Next

func (it *Iterator[T]) Next() bool

Next returns the next element of the iterator.

func (*Iterator[T]) Prev

func (it *Iterator[T]) Prev() bool

Prev returns the previous element of the iterator.

func (*Iterator[T]) Value

func (it *Iterator[T]) Value() T

Value returns the current element's value.

type List

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

func Map

func Map[K comparable, V comparable](l *List[K], f func(index int, value K) V) *List[V]

Map invokes the given function once for each element and returns a container containing the values returned by the given function.

func New

func New[T comparable](values ...T) *List[T]

New returns a new list.

func (*List[T]) Add

func (l *List[T]) Add(values ...T)

Add adds values to the list.

func (*List[T]) All

func (l *List[T]) All(f func(index int, value T) bool) bool

All passes each element of the container to the given function and returns true if the function returns true for all elements.

func (*List[T]) Any

func (l *List[T]) Any(f func(index int, value T) bool) bool

Any passes each element of the container to the given function and returns true if the function ever returns true for any element.

func (*List[T]) Append

func (l *List[T]) Append(values ...T)

Append adds values to the end of the list.

func (*List[T]) Clear

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

Clear removes all values from the list.

func (*List[T]) Contains

func (l *List[T]) Contains(values ...T) bool

Contains checks if the list contains the value.

func (*List[T]) Each

func (l *List[T]) Each(f func(index int, value T))

Each calls the given function once for each element, passing that element's index and value.

func (*List[T]) Empty

func (l *List[T]) Empty() bool

Empty returns true if the list is empty.

func (*List[T]) Filter

func (l *List[T]) Filter(f func(index int, value T) bool) *List[T]

Filter returns a new container containing all elements for which the given function returns a true value.

func (*List[T]) Find

func (l *List[T]) Find(f func(index int, value T) bool) (_ int, t T)

Find passes each element of the container to the given function and returns the first (index,value) for which the function is true or -1,nil otherwise if no element matches the criteria.

func (*List[T]) FromJSON

func (l *List[T]) FromJSON(data []byte) error

FromJSON populates list's elements from the input JSON representation.

func (*List[T]) Get

func (l *List[T]) Get(i int) (t T, _ bool)

Get returns the value at index i.

func (*List[T]) IndexOf

func (l *List[T]) IndexOf(value T) int

IndexOf returns the index of the first occurrence of the value.

func (*List[T]) Insert

func (l *List[T]) Insert(i int, values ...T)

Insert inserts the value at the given index.

func (*List[T]) Iterator

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

func (*List[T]) Prepend

func (l *List[T]) Prepend(values ...T)

Prepend adds values to the beginning of the list.

func (*List[T]) Remove

func (l *List[T]) Remove(i int) (t T, _ bool)

Remove removes the value at index i.

func (*List[T]) Set

func (l *List[T]) Set(i int, value T)

Set sets the value at index i.

func (*List[T]) Size

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

Size returns the number of values in the list.

func (*List[T]) Sort

func (l *List[T]) Sort(c utils.Comparator[T])

Sort sorts the list.

func (*List[T]) String

func (l *List[T]) String() string

String returns a string representation of container

func (*List[T]) Swap

func (l *List[T]) Swap(i, j int)

Swap swaps the values at the given indices.

func (*List[T]) ToJSON

func (l *List[T]) ToJSON() ([]byte, error)

ToJSON outputs the JSON representation of list's elements.

func (*List[T]) Values

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

Values returns a slice of all the values in the list.

Jump to

Keyboard shortcuts

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