arraylist

package
v0.3.0 Latest Latest
Warning

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

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

Documentation

Overview

Package arraylist implements the array 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.3.0

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

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

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

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

PERF: Maybe an unsafe version is useful here Get implements ds.RWOrdCompBidRandCollIterator

func (*Iterator[T]) GetAt added in v0.3.0

func (it *Iterator[T]) GetAt(i int) (value T, found bool)

PERF: Maybe an unsafe version is useful here GetAt implements ds.RWOrdCompBidRandCollIterator

func (*Iterator[T]) Index

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

Index implements ds.RWOrdCompBidRandCollIterator

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

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

IsAfter implements ds.RWOrdCompBidRandCollIterator

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

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

IsBefore implements ds.RWOrdCompBidRandCollIterator

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

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

IsBegin implements ds.RWOrdCompBidRandCollIterator

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

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

IsEnd implements ds.RWOrdCompBidRandCollIterator

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

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

IsEqual implements ds.RWOrdCompBidRandCollIterator

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

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

IsFirst implements ds.RWOrdCompBidRandCollIterator

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

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

IsLast implements ds.RWOrdCompBidRandCollIterator

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

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

IsValid implements ds.RWOrdCompBidRandCollIterator

func (*Iterator[T]) MoveBy added in v0.3.0

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

MoveBy implements ds.RWOrdCompBidRandCollIterator

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

func (it *Iterator[T]) MoveTo(i int)

MoveTo implements ds.RWOrdCompBidRandCollIterator

func (*Iterator[T]) Next

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

Next implements ds.RWOrdCompBidRandCollIterator

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

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

NextN implements ds.RWOrdCompBidRandCollIterator

func (*Iterator[T]) Previous added in v0.3.0

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

Previous implements ds.RWOrdCompBidRandCollIterator

func (*Iterator[T]) PreviousN added in v0.3.0

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

PreviousN implements ds.RWOrdCompBidRandCollIterator

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

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

PERF: Maybe an unsafe version is useful here Set implements ds.RWOrdCompBidRandCollIterator

func (*Iterator[T]) SetAt added in v0.3.0

func (it *Iterator[T]) SetAt(i int, value T) bool

PERF: Maybe an unsafe version is useful here SetAt implements ds.RWOrdCompBidRandCollIterator

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

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

Size implements ds.RWOrdCompBidRandCollIterator

type List

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

TODO: Try and reimplement methods through iterator TODO: Allow access to underlying slice TODO: Rename to DynamicArray List holds the elements in a slice.

func New

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

TODO: Implement NewFromSlice() method which only copies slice header and not items New instantiates a new list and adds the passed values, if any, to the list.

func (*List[T]) Add

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

Add appends a value at the end of the list.

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

func (list *List[T]) Begin() ds.RWOrdCompBidRandCollIterator[T, int]

Begin returns an initialized iterator, which points to one element before it's first. Unless Next() is called, the iterator is in an invalid state.

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

PERF: Maybe we can provide separated implementations of the data structures (e.g. BasicList) through code generation, which are constrained with comparable PERF: Iterate over elements only once and keep counter of found values Contains checks if elements (one or more) are present in the set. All elements 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.3.0

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

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.3.0

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

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, wasFound 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

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.3.0

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

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.3.0

func (list *List[T]) NewIterator(list_ *List[T], index int) *Iterator[T]

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

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

func (list *List[T]) NewReverseIterator(list_ *List[T], index int) *ReverseIterator[T]

NewReverseIterator 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()

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

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

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

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

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

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

func (*List[T]) Remove

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

TODO: Implement RemoveStable which does a swap and shrink Remove removes the element at the given index from the list.

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

func (list *List[T]) ReverseBegin() ds.RWOrdCompBidRevRandCollIterator[T, int]

ReverseBegin returns an initialized, reversed iterator, which points to one element before it's first. Unless Next() is called, the iterator is in an invalid state.

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

func (list *List[T]) ReverseEnd() ds.RWOrdCompBidRevRandCollIterator[T, int]

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

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

func (list *List[T]) ReverseFirst() ds.RWOrdCompBidRevRandCollIterator[T, int]

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

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

func (list *List[T]) ReverseLast() ds.RWOrdCompBidRevRandCollIterator[T, int]

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

func (*List[T]) Set

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

Set the 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 sorts values (in-place) using.

func (*List[T]) Swap

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

Swap swaps the two values at the specified positions.

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

type ReverseIterator added in v0.3.0

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

ReverseIterator holding the iterator's state

func (*ReverseIterator[T]) DistanceTo added in v0.3.0

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

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

func (*ReverseIterator[T]) Get added in v0.3.0

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

Get implements ds.RWOrdCompBidRandCollReverseIterator

func (*ReverseIterator[T]) GetAt added in v0.3.0

func (it *ReverseIterator[T]) GetAt(i int) (value T, found bool)

PERF: Maybe an unsafe version is useful here GetAt implements ds.RWOrdCompBidRandCollIterator

func (*ReverseIterator[T]) Index added in v0.3.0

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

Index implements ds.RWOrdCompBidRandCollReverseIterator

func (*ReverseIterator[T]) IsAfter added in v0.3.0

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

IsAfter implements ds.RWOrdCompBidRandCollReverseIterator

func (*ReverseIterator[T]) IsBefore added in v0.3.0

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

IsBefore implements ds.RWOrdCompBidRandCollReverseIterator

func (*ReverseIterator[T]) IsBegin added in v0.3.0

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

IsBegin implements ds.ReverseIterator

func (*ReverseIterator[T]) IsEnd added in v0.3.0

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

IsEnd implements ds.ReverseIterator

func (*ReverseIterator[T]) IsEqual added in v0.3.0

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

IsEqual implements ds.RWOrdCompBidRandCollReverseIterator

func (*ReverseIterator[T]) IsFirst added in v0.3.0

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

IsFirst implements ds.ReverseIterator

func (*ReverseIterator[T]) IsLast added in v0.3.0

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

IsLast implements ds.ReverseIterator

func (*ReverseIterator[T]) IsValid added in v0.3.0

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

IsValid implements ds.RWOrdCompBidRandCollReverseIterator

func (*ReverseIterator[T]) MoveBy added in v0.3.0

func (it *ReverseIterator[T]) MoveBy(n int)

MoveBy implements ds.RWOrdCompBidRandCollReverseIterator

func (*ReverseIterator[T]) MoveTo added in v0.3.0

func (it *ReverseIterator[T]) MoveTo(i int)

MoveTo implements ds.RWOrdCompBidRandCollReverseIterator

func (*ReverseIterator[T]) Next added in v0.3.0

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

Next implements ds.RWOrdCompBidRandCollReverseIterator

func (*ReverseIterator[T]) NextN added in v0.3.0

func (it *ReverseIterator[T]) NextN(i int)

NextN implements ds.RWOrdCompBidRandCollReverseIterator

func (*ReverseIterator[T]) Previous added in v0.3.0

func (it *ReverseIterator[T]) Previous()

Previous implements ds.RWOrdCompBidRandCollReverseIterator

func (*ReverseIterator[T]) PreviousN added in v0.3.0

func (it *ReverseIterator[T]) PreviousN(n int)

PreviousN implements ds.RWOrdCompBidRandCollReverseIterator

func (*ReverseIterator[T]) Set added in v0.3.0

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

Set implements ds.RWOrdCompBidRandCollReverseIterator

func (*ReverseIterator[T]) SetAt added in v0.3.0

func (it *ReverseIterator[T]) SetAt(i int, value T) bool

PERF: Maybe an unsafe version is useful here SetAt implements ds.RWOrdCompBidRandCollIterator

func (*ReverseIterator[T]) Size added in v0.3.0

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

Size implements ds.RWOrdCompBidRandCollReverseIterator

Jump to

Keyboard shortcuts

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