arraylist

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 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

View Source
const (
	ShrinkThresholdPercent  = float32(0.25) // shrink when cap * ShrinkThresholdPercent > len (0 means never shrink)
	ShrinkThresholdAbsolute = 100           // shrink when cap - len >= ShrinkThresholdAbsolute
	ShrinkFactor            = float32(0.5)  // shrink by ShrinkFactor * cap - len
)

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

If other is of type IndexedIterator, IndexedIterator.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)

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

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

func (*Iterator[T]) Index

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

func (*Iterator[T]) Next

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

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

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

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

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

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

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

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

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

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

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

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

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

type List

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

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

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

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

func NewFromIterators added in v0.6.0

func NewFromIterators[T any](begin 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.4.0

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

NewFromSlice instantiates a new list containing the provided slice.

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

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

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

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

func (list *List[T]) First() ds.ReadWriteOrdCompBidRandCollIterator[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, 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]) GetSlice added in v0.4.0

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

GetSlice returns the underlying slice.

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

func (list *List[T]) NewIterator(index int, size 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(index int, size int) *ReverseIterator[T]

NewIterator 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) (popped []T)

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

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

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

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

Add appends a value at the end of the list.

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)

Remove removes the element at the given index from the list. The order of the elements is allowed to be changed for performance reasons.

func (*List[T]) RemoveStable added in v0.4.0

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

RemoveStable removes the element at the given index from the list. THe order of the elements is NOT allowed to be changed.

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

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

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.ReadWriteOrdCompBidRandCollIterator[int, T]

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.ReadWriteOrdCompBidRandCollIterator[int, T]

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.ReadWriteOrdCompBidRandCollIterator[int, T]

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]) ShrinkToFit added in v0.5.0

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

ShrinkToFit shrinks the array so that len == cap.

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]) TryShrink added in v0.5.0

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

TryShrink the array if possible/worthwhile. Shrinking is worthwile if: cap - len > ShrinkThresholdAbsolute and cap * ShrinkThresholdPercent > len

To reduce the number of reslices upon appending, the new length will be len + ((cap - len) * ShrinkFactor).

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
}

Iterator holding the iterator's state

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

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

If other is of type IndexedIterator, IndexedIterator.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)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

func (it *ReverseIterator[T]) NextN(n int) bool

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

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

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

func (it *ReverseIterator[T]) PreviousN(i int) bool

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

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

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

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

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

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

Jump to

Keyboard shortcuts

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