singlylinkedlist

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2022 License: BSD-2-Clause, ISC Imports: 6 Imported by: 129

Documentation

Overview

Package singlylinkedlist implements the singly-linked list.

Structure is not thread safe.

Reference: https://en.wikipedia.org/wiki/List_%28abstract_data_type%29

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Iterator

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

Iterator holding the iterator's state

func (*Iterator) Begin added in v1.2.0

func (iterator *Iterator) Begin()

Begin resets the iterator to its initial state (one-before-first) Call Next() to fetch the first element if any.

func (*Iterator) First added in v1.2.0

func (iterator *Iterator) First() bool

First moves the iterator to the first element and returns true if there was a first element in the container. If First() returns true, then first element's index and value can be retrieved by Index() and Value(). Modifies the state of the iterator.

func (*Iterator) Index

func (iterator *Iterator) Index() int

Index returns the current element's index. Does not modify the state of the iterator.

func (*Iterator) Next

func (iterator *Iterator) Next() bool

Next moves the iterator to the next element and returns true if there was a next element in the container. If Next() returns true, then next element's index and value can be retrieved by Index() and Value(). If Next() was called for the first time, then it will point the iterator to the first element if it exists. Modifies the state of the iterator.

func (*Iterator) NextTo added in v1.13.0

func (iterator *Iterator) NextTo(f func(index int, value interface{}) bool) bool

NextTo moves the iterator to the next element from current position that satisfies the condition given by the passed function, and returns true if there was a next element in the container. If NextTo() returns true, then next element's index and value can be retrieved by Index() and Value(). Modifies the state of the iterator.

func (*Iterator) Value

func (iterator *Iterator) Value() interface{}

Value returns the current element's value. Does not modify the state of the iterator.

type List

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

List holds the elements, where each element points to the next element

func New

func New(values ...interface{}) *List

New instantiates a new list and adds the passed values, if any, to the list

func (*List) Add

func (list *List) Add(values ...interface{})

Add appends a value (one or more) at the end of the list (same as Append())

func (*List) All

func (list *List) All(f func(index int, value interface{}) 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) Any

func (list *List) Any(f func(index int, value interface{}) 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) Append

func (list *List) Append(values ...interface{})

Append appends a value (one or more) at the end of the list (same as Add())

func (*List) Clear

func (list *List) Clear()

Clear removes all elements from the list.

func (*List) Contains

func (list *List) Contains(values ...interface{}) bool

Contains checks if values (one or more) are present in the set. All values have to be present in the set for the method to return true. Performance time complexity of n^2. Returns true if no arguments are passed at all, i.e. set is always super-set of empty set.

func (*List) Each

func (list *List) Each(f func(index int, value interface{}))

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

func (*List) Empty

func (list *List) Empty() bool

Empty returns true if list does not contain any elements.

func (*List) Find

func (list *List) Find(f func(index int, value interface{}) bool) (index int, value interface{})

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) FromJSON added in v1.9.0

func (list *List) FromJSON(data []byte) error

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

func (*List) Get

func (list *List) Get(index int) (interface{}, bool)

Get returns the element at index. Second return parameter is true if index is within bounds of the array and array is not empty, otherwise false.

func (*List) IndexOf added in v1.10.0

func (list *List) IndexOf(value interface{}) int

IndexOf returns index of provided element

func (*List) Insert

func (list *List) Insert(index int, values ...interface{})

Insert inserts values at specified index position shifting the value at that position (if any) and any subsequent elements to the right. Does not do anything if position is negative or bigger than list's size Note: position equal to list's size is valid, i.e. append.

func (*List) Iterator

func (list *List) Iterator() Iterator

Iterator returns a stateful iterator whose values can be fetched by an index.

func (*List) Map

func (list *List) Map(f func(index int, value interface{}) interface{}) *List

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

func (*List) Prepend

func (list *List) Prepend(values ...interface{})

Prepend prepends a values (or more)

func (*List) Remove

func (list *List) Remove(index int)

Remove removes the element at the given index from the list.

func (*List) Select

func (list *List) Select(f func(index int, value interface{}) bool) *List

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

func (*List) Set added in v1.10.0

func (list *List) Set(index int, value interface{})

Set value at specified index Does not do anything if position is negative or bigger than list's size Note: position equal to list's size is valid, i.e. append.

func (*List) Size

func (list *List) Size() int

Size returns number of elements within the list.

func (*List) Sort

func (list *List) Sort(comparator utils.Comparator)

Sort sort values (in-place) using.

func (*List) String

func (list *List) String() string

String returns a string representation of container

func (*List) Swap

func (list *List) Swap(i, j int)

Swap swaps values of two elements at the given indices.

func (*List) ToJSON added in v1.9.0

func (list *List) ToJSON() ([]byte, error)

ToJSON outputs the JSON representation of list's elements.

func (*List) Values

func (list *List) Values() []interface{}

Values returns all elements in the list.

Jump to

Keyboard shortcuts

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