singlylinkedlist

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2022 License: BSD-2-Clause, ISC Imports: 6 Imported by: 0

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[T any] struct {
	// contains filtered or unexported fields
}

Iterator holding the iterator's state

func (*Iterator[T]) DistanceTo added in v0.7.0

func (it *Iterator[T]) DistanceTo(other ds.OrderedIterator) int

DistanceTo implements ds.ReadWriteOrdCompBidRandCollIterator If other is of type IndexedIterator, IndexedIterator.Index() will be used, possibly executing in O(1)

func (*Iterator[T]) Get added in v0.7.0

func (it *Iterator[T]) Get() (value T, found bool)

Get implements ds.ReadWriteOrdCompBidRandCollIterator

func (*Iterator[T]) Index

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

Index implements ds.ReadWriteOrdCompBidRandCollIterator

func (*Iterator[T]) IsAfter added in v0.7.0

func (it *Iterator[T]) IsAfter(other ds.OrderedIterator) bool

IsAfter implements ds.ReadWriteOrdCompBidRandCollIterator

func (*Iterator[T]) IsBefore added in v0.7.0

func (it *Iterator[T]) IsBefore(other ds.OrderedIterator) bool

IsBefore implements ds.ReadWriteOrdCompBidRandCollIterator

func (*Iterator[T]) IsBegin added in v0.7.0

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

IsBegin implements ds.ReadWriteOrdCompBidRandCollIterator

func (*Iterator[T]) IsEnd added in v0.7.0

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

IsEnd implements ds.ReadWriteOrdCompBidRandCollIterator

func (*Iterator[T]) IsEqual added in v0.7.0

func (it *Iterator[T]) IsEqual(other ds.ComparableIterator) bool

IsEqual implements ds.ReadWriteOrdCompBidRandCollIterator

func (*Iterator[T]) IsFirst added in v0.7.0

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

IsFirst implements ds.ReadWriteOrdCompBidRandCollIterator

func (*Iterator[T]) IsLast added in v0.7.0

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

IsLast implements ds.ReadWriteOrdCompBidRandCollIterator

func (*Iterator[T]) IsValid added in v0.7.0

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

IsValid implements ds.ReadWriteOrdCompBidRandCollIterator

func (*Iterator[T]) MoveTo added in v0.7.0

func (it *Iterator[T]) MoveTo(n int) bool

MoveTo implements ds.ReadWriteOrdCompBidRandCollIterator

func (*Iterator[T]) Next

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

Next implements ds.ReadWriteOrdCompBidRandCollIterator

func (*Iterator[T]) NextN added in v0.7.0

func (it *Iterator[T]) NextN(n int)

NextN implements ds.ReadWriteOrdCompBidRandCollIterator

func (*Iterator[T]) Set added in v0.7.0

func (it *Iterator[T]) Set(value T) bool

Set implements ds.ReadWriteOrdCompBidRandCollIterator

func (*Iterator[T]) Size added in v0.7.0

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

Size implements ds.ReadWriteOrdCompBidRandCollIterator

type List

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

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

func New

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

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

func NewFromIterator added in v0.7.0

func NewFromIterator[T any](it ds.ReadCompForIterator[T]) *List[T]

NewFromIterator instantiates a new list containing the elements provided by the passed iterator.

func NewFromIterators added in v0.7.0

func NewFromIterators[T any](first ds.ReadCompForIterator[T], end ds.ComparableIterator) *List[T]

NewFromIterators instantiates a new list containing the elements provided by first, until it is equal to end. end is a sentinel and not included.

func NewFromSlice added in v0.7.0

func NewFromSlice[T any](slice []T) *List[T]

NewFromSlice instantiates a new list containing the provided slice.

func (*List[T]) Clear

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

Clear removes all elements from the list.

func (*List[T]) Contains

func (list *List[T]) Contains(comparator utils.Comparator[T], values ...T) 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[T]) End added in v0.7.0

func (list *List[T]) End() ds.ReadWriteOrdCompForRandCollIterator[int, T]

End returns an initialized iterator, which points to one element afrer it's last. Unless Previous() is called, the iterator is in an invalid state.

func (*List[T]) First added in v0.7.0

func (list *List[T]) First() ds.ReadWriteOrdCompForRandCollIterator[int, T]

First returns an initialized iterator, which points to it's first element.

func (*List[T]) FromJSON

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

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

func (*List[T]) Get

func (list *List[T]) Get(index int) (value T, found 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[T]) GetValues added in v0.3.0

func (list *List[T]) GetValues() []T

Values returns all elements in the list.

func (*List[T]) IndexOf

func (list *List[T]) IndexOf(comparator utils.Comparator[T], value T) int

IndexOf returns index of provided element

func (*List[T]) Insert

func (list *List[T]) Insert(index int, values ...T)

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[T]) IsEmpty added in v0.3.0

func (list *List[T]) IsEmpty() bool

Empty returns true if list does not contain any elements.

func (*List[T]) Last added in v0.7.0

func (list *List[T]) Last() ds.ReadWriteOrdCompForRandCollIterator[int, T]

Last returns an initialized iterator, which points to it's last element.

func (*List[T]) MarshalJSON

func (list *List[T]) MarshalJSON() ([]byte, error)

MarshalJSON @implements json.Marshaler

func (*List[T]) NewIterator added in v0.7.0

func (list *List[T]) NewIterator(l *List[T], position int) *Iterator[T]

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

func (*List[T]) PopBack added in v0.3.0

func (list *List[T]) PopBack(n int)

func (*List[T]) PopFront added in v0.3.0

func (list *List[T]) PopFront(n int)

func (*List[T]) PushBack added in v0.3.0

func (list *List[T]) PushBack(values ...T)

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

func (*List[T]) PushFront added in v0.3.0

func (list *List[T]) PushFront(values ...T)

Prepend prepends a values (or more)

func (*List[T]) Remove

func (list *List[T]) Remove(index int)

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

func (*List[T]) Set

func (list *List[T]) Set(index int, value T)

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[T]) Size

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

Size returns number of elements within the list.

func (*List[T]) Sort

func (list *List[T]) Sort(comparator utils.Comparator[T])

Sort sort values (in-place) using.

func (*List[T]) Swap

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

Swap swaps values of two elements at the given indices.

func (*List[T]) ToJSON

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

ToJSON outputs the JSON representation of list's elements.

func (*List[T]) ToString added in v0.3.0

func (list *List[T]) ToString() string

String returns a string representation of container

func (*List[T]) UnmarshalJSON

func (list *List[T]) UnmarshalJSON(bytes []byte) error

UnmarshalJSON @implements json.Unmarshaler

Jump to

Keyboard shortcuts

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