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
- type Iterator
- func (it *Iterator[T]) DistanceTo(other ds.OrderedIterator) int
- func (it *Iterator[T]) Get() (value T, found bool)
- func (it *Iterator[T]) GetAt(i int) (value T, found bool)
- func (it *Iterator[T]) Index() (int, bool)
- func (it *Iterator[T]) IsAfter(other ds.OrderedIterator) bool
- func (it *Iterator[T]) IsBefore(other ds.OrderedIterator) bool
- func (it *Iterator[T]) IsBegin() bool
- func (it *Iterator[T]) IsEnd() bool
- func (it *Iterator[T]) IsEqual(other ds.ComparableIterator) bool
- func (it *Iterator[T]) IsFirst() bool
- func (it *Iterator[T]) IsLast() bool
- func (it *Iterator[T]) IsValid() bool
- func (it *Iterator[T]) MoveBy(n int) bool
- func (it *Iterator[T]) MoveTo(i int) bool
- func (it *Iterator[T]) Next() bool
- func (it *Iterator[T]) NextN(i int) bool
- func (it *Iterator[T]) Previous() bool
- func (it *Iterator[T]) PreviousN(n int) bool
- func (it *Iterator[T]) Set(value T) bool
- func (it *Iterator[T]) SetAt(i int, value T) bool
- func (it *Iterator[T]) Size() int
- type List
- func (list *List[T]) Begin() ds.ReadWriteOrdCompBidRandCollIterator[int, T]
- func (list *List[T]) Clear()
- func (list *List[T]) Contains(comparator utils.Comparator[T], values ...T) bool
- func (list *List[T]) End() ds.ReadWriteOrdCompBidRandCollIterator[int, T]
- func (list *List[T]) First() ds.ReadWriteOrdCompBidRandCollIterator[int, T]
- func (list *List[T]) FromJSON(data []byte) error
- func (list *List[T]) Get(index int) (value T, wasFound bool)
- func (list *List[T]) GetSlice() []T
- func (list *List[T]) GetValues() []T
- func (list *List[T]) IndexOf(comparator utils.Comparator[T], value T) int
- func (list *List[T]) Insert(index int, values ...T)
- func (list *List[T]) IsEmpty() bool
- func (list *List[T]) Last() ds.ReadWriteOrdCompBidRandCollIterator[int, T]
- func (list *List[T]) MarshalJSON() ([]byte, error)
- func (list *List[T]) NewIterator(l *List[T], index int) *Iterator[T]
- func (list *List[T]) NewReverseIterator(l *List[T], index int) *ReverseIterator[T]
- func (list *List[T]) PopBack(n int)
- func (list *List[T]) PopFront(n int)
- func (list *List[T]) PushBack(values ...T)
- func (list *List[T]) PushFront(values ...T)
- func (list *List[T]) Remove(index int)
- func (list *List[T]) RemoveStable(index int)
- func (list *List[T]) ReverseBegin() ds.ReadWriteOrdCompBidRandCollIterator[int, T]
- func (list *List[T]) ReverseEnd() ds.ReadWriteOrdCompBidRandCollIterator[int, T]
- func (list *List[T]) ReverseFirst() ds.ReadWriteOrdCompBidRandCollIterator[int, T]
- func (list *List[T]) ReverseLast() ds.ReadWriteOrdCompBidRandCollIterator[int, T]
- func (list *List[T]) Set(index int, value T)
- func (list *List[T]) ShrinkToFit()
- func (list *List[T]) Size() int
- func (list *List[T]) Sort(comparator utils.Comparator[T])
- func (list *List[T]) Swap(i, j int)
- func (list *List[T]) ToJSON() ([]byte, error)
- func (list *List[T]) ToString() string
- func (list *List[T]) TryShrink()
- func (list *List[T]) UnmarshalJSON(bytes []byte) error
- type ReverseIterator
- func (it *ReverseIterator[T]) DistanceTo(other ds.OrderedIterator) int
- func (it *ReverseIterator[T]) Get() (value T, found bool)
- func (it *ReverseIterator[T]) GetAt(i int) (value T, found bool)
- func (it *ReverseIterator[T]) Index() (int, bool)
- func (it *ReverseIterator[T]) IsAfter(other ds.OrderedIterator) bool
- func (it *ReverseIterator[T]) IsBefore(other ds.OrderedIterator) bool
- func (it *ReverseIterator[T]) IsBegin() bool
- func (it *ReverseIterator[T]) IsEnd() bool
- func (it *ReverseIterator[T]) IsEqual(other ds.ComparableIterator) bool
- func (it *ReverseIterator[T]) IsFirst() bool
- func (it *ReverseIterator[T]) IsLast() bool
- func (it *ReverseIterator[T]) IsValid() bool
- func (it *ReverseIterator[T]) MoveBy(n int) bool
- func (it *ReverseIterator[T]) MoveTo(i int) bool
- func (it *ReverseIterator[T]) Next() bool
- func (it *ReverseIterator[T]) NextN(n int) bool
- func (it *ReverseIterator[T]) Previous() bool
- func (it *ReverseIterator[T]) PreviousN(i int) bool
- func (it *ReverseIterator[T]) Set(value T) bool
- func (it *ReverseIterator[T]) SetAt(i int, value T) bool
- func (it *ReverseIterator[T]) Size() int
Constants ¶
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
DistanceTo implements ds.ReadWriteOrdCompBidRandCollIterator If other is of type IndexedIterator, IndexedIterator.Index() will be used, possibly executing in O(1)
func (*Iterator[T]) IsAfter ¶ added in v0.3.0
func (it *Iterator[T]) IsAfter(other ds.OrderedIterator) bool
IsAfter implements ds.ReadWriteOrdCompBidRandCollIterator
func (*Iterator[T]) IsBefore ¶ added in v0.3.0
func (it *Iterator[T]) IsBefore(other ds.OrderedIterator) bool
IsBefore implements ds.ReadWriteOrdCompBidRandCollIterator
func (*Iterator[T]) IsBegin ¶ added in v0.3.0
IsBegin implements ds.ReadWriteOrdCompBidRandCollIterator
func (*Iterator[T]) IsEqual ¶ added in v0.3.0
func (it *Iterator[T]) IsEqual(other ds.ComparableIterator) bool
IsEqual implements ds.ReadWriteOrdCompBidRandCollIterator
func (*Iterator[T]) IsFirst ¶ added in v0.3.0
IsFirst implements ds.ReadWriteOrdCompBidRandCollIterator
func (*Iterator[T]) IsLast ¶ added in v0.3.0
IsLast implements ds.ReadWriteOrdCompBidRandCollIterator
func (*Iterator[T]) IsValid ¶ added in v0.3.0
IsValid implements ds.ReadWriteOrdCompBidRandCollIterator
func (*Iterator[T]) MoveBy ¶ added in v0.3.0
MoveBy implements ds.ReadWriteOrdCompBidRandCollIterator
func (*Iterator[T]) MoveTo ¶ added in v0.3.0
MoveTo implements ds.ReadWriteOrdCompBidRandCollIterator
func (*Iterator[T]) Previous ¶ added in v0.3.0
Previous implements ds.ReadWriteOrdCompBidRandCollIterator
func (*Iterator[T]) PreviousN ¶ added in v0.3.0
PreviousN implements ds.ReadWriteOrdCompBidRandCollIterator
type List ¶
type List[T any] struct { // contains filtered or unexported fields }
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
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]) 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]) Get ¶
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]) Insert ¶
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]) 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 ¶
MarshalJSON @implements json.Marshaler
func (*List[T]) NewIterator ¶ added in v0.3.0
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(l *List[T], index int) *ReverseIterator[T]
NewIterator returns a stateful iterator whose values can be fetched by an index.
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]) Remove ¶
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
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 ¶
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]) Sort ¶
func (list *List[T]) Sort(comparator utils.Comparator[T])
Sort sorts values (in-place) using.
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 ¶
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
DistanceTo implements ds.ReadWriteOrdCompBidRandCollIterator 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)
Get implements ds.ReadWriteOrdCompBidRandCollIterator
func (*ReverseIterator[T]) GetAt ¶ added in v0.3.0
func (it *ReverseIterator[T]) GetAt(i int) (value T, found bool)
GetAt implements ds.ReadWriteOrdCompBidRandCollIterator
func (*ReverseIterator[T]) Index ¶ added in v0.3.0
func (it *ReverseIterator[T]) Index() (int, bool)
Index implements ds.ReadWriteOrdCompBidRandCollIterator
func (*ReverseIterator[T]) IsAfter ¶ added in v0.3.0
func (it *ReverseIterator[T]) IsAfter(other ds.OrderedIterator) bool
IsAfter implements ds.ReadWriteOrdCompBidRandCollIterator
func (*ReverseIterator[T]) IsBefore ¶ added in v0.3.0
func (it *ReverseIterator[T]) IsBefore(other ds.OrderedIterator) bool
IsBefore implements ds.ReadWriteOrdCompBidRandCollIterator
func (*ReverseIterator[T]) IsBegin ¶ added in v0.3.0
func (it *ReverseIterator[T]) IsBegin() bool
IsBegin implements ds.ReadWriteOrdCompBidRandCollIterator
func (*ReverseIterator[T]) IsEnd ¶ added in v0.3.0
func (it *ReverseIterator[T]) IsEnd() bool
IsEnd implements ds.ReadWriteOrdCompBidRandCollIterator
func (*ReverseIterator[T]) IsEqual ¶ added in v0.3.0
func (it *ReverseIterator[T]) IsEqual(other ds.ComparableIterator) bool
IsEqual implements ds.ReadWriteOrdCompBidRandCollIterator
func (*ReverseIterator[T]) IsFirst ¶ added in v0.3.0
func (it *ReverseIterator[T]) IsFirst() bool
IsFirst implements ds.ReadWriteOrdCompBidRandCollIterator
func (*ReverseIterator[T]) IsLast ¶ added in v0.3.0
func (it *ReverseIterator[T]) IsLast() bool
IsLast implements ds.ReadWriteOrdCompBidRandCollIterator
func (*ReverseIterator[T]) IsValid ¶ added in v0.3.0
func (it *ReverseIterator[T]) IsValid() bool
IsValid implements ds.ReadWriteOrdCompBidRandCollIterator
func (*ReverseIterator[T]) MoveBy ¶ added in v0.3.0
func (it *ReverseIterator[T]) MoveBy(n int) bool
MoveBy implements ds.ReadWriteOrdCompBidRandCollIterator
func (*ReverseIterator[T]) MoveTo ¶ added in v0.3.0
func (it *ReverseIterator[T]) MoveTo(i int) bool
MoveTo implements ds.ReadWriteOrdCompBidRandCollIterator
func (*ReverseIterator[T]) Next ¶ added in v0.3.0
func (it *ReverseIterator[T]) Next() bool
Previous implements ds.ReadWriteOrdCompBidRandCollIterator
func (*ReverseIterator[T]) NextN ¶ added in v0.3.0
func (it *ReverseIterator[T]) NextN(n int) bool
PreviousN implements ds.ReadWriteOrdCompBidRandCollIterator
func (*ReverseIterator[T]) Previous ¶ added in v0.3.0
func (it *ReverseIterator[T]) Previous() bool
Next implements ds.ReadWriteOrdCompBidRandCollIterator
func (*ReverseIterator[T]) PreviousN ¶ added in v0.3.0
func (it *ReverseIterator[T]) PreviousN(i int) bool
NextN implements ds.ReadWriteOrdCompBidRandCollIterator
func (*ReverseIterator[T]) Set ¶ added in v0.3.0
func (it *ReverseIterator[T]) Set(value T) bool
Set implements ds.ReadWriteOrdCompBidRandCollIterator
func (*ReverseIterator[T]) SetAt ¶ added in v0.3.0
func (it *ReverseIterator[T]) SetAt(i int, value T) bool
SetAt implements ds.ReadWriteOrdCompBidRandCollIterator
func (*ReverseIterator[T]) Size ¶ added in v0.3.0
func (it *ReverseIterator[T]) Size() int
Size implements ds.ReadWriteOrdCompBidRandCollIterator