Documentation
¶
Overview ¶
Package arraystack implements a stack backed by array list.
Structure is not thread safe.
Reference: https://en.wikipedia.org/wiki/Stack_%28abstract_data_type%29#Array
Index ¶
- 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)
- func (it *Iterator[T]) MoveTo(i int) bool
- func (it *Iterator[T]) Next()
- func (it *Iterator[T]) NextN(i int)
- func (it *Iterator[T]) Previous()
- func (it *Iterator[T]) PreviousN(n int)
- 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 Stack
- func (set *Stack[T]) Begin() ds.ReadWriteOrdCompBidRandCollIterator[int, T]
- func (stack *Stack[T]) Clear()
- func (set *Stack[T]) End() ds.ReadWriteOrdCompBidRandCollIterator[int, T]
- func (set *Stack[T]) First() ds.ReadWriteOrdCompBidRandCollIterator[int, T]
- func (stack *Stack[T]) FromJSON(data []byte) error
- func (stack *Stack[T]) GetValues() []T
- func (stack *Stack[T]) IsEmpty() bool
- func (set *Stack[T]) Last() ds.ReadWriteOrdCompBidRandCollIterator[int, T]
- func (stack *Stack[T]) MarshalJSON() ([]byte, error)
- func (list *Stack[T]) NewIterator(list_ *Stack[T], index int) *Iterator[T]
- func (stack *Stack[T]) Peek() (value T, ok bool)
- func (stack *Stack[T]) Pop() (value T, ok bool)
- func (stack *Stack[T]) Push(value T)
- func (stack *Stack[T]) Size() int
- func (stack *Stack[T]) ToJSON() ([]byte, error)
- func (stack *Stack[T]) ToString() string
- func (stack *Stack[T]) UnmarshalJSON(bytes []byte) error
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.11.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]) GetAt ¶ added in v0.11.0
GetAt implements ds.ReadWriteOrdCompBidRandCollIterator
func (*Iterator[T]) IsAfter ¶ added in v0.11.0
func (it *Iterator[T]) IsAfter(other ds.OrderedIterator) bool
IsAfter implements ds.ReadWriteOrdCompBidRandCollIterator
func (*Iterator[T]) IsBefore ¶ added in v0.11.0
func (it *Iterator[T]) IsBefore(other ds.OrderedIterator) bool
IsBefore implements ds.ReadWriteOrdCompBidRandCollIterator
func (*Iterator[T]) IsBegin ¶ added in v0.11.0
IsBegin implements ds.ReadWriteOrdCompBidRandCollIterator
func (*Iterator[T]) IsEnd ¶ added in v0.11.0
IsEnd implements ds.ReadWriteOrdCompBidRandCollIterator
func (*Iterator[T]) IsEqual ¶ added in v0.11.0
func (it *Iterator[T]) IsEqual(other ds.ComparableIterator) bool
IsEqual implements ds.ReadWriteOrdCompBidRandCollIterator
func (*Iterator[T]) IsFirst ¶ added in v0.11.0
IsFirst implements ds.ReadWriteOrdCompBidRandCollIterator
func (*Iterator[T]) IsLast ¶ added in v0.11.0
IsLast implements ds.ReadWriteOrdCompBidRandCollIterator
func (*Iterator[T]) IsValid ¶ added in v0.11.0
IsValid implements ds.ReadWriteOrdCompBidRandCollIterator
func (*Iterator[T]) MoveBy ¶ added in v0.11.0
MoveBy implements ds.ReadWriteOrdCompBidRandCollIterator
func (*Iterator[T]) MoveTo ¶ added in v0.11.0
MoveTo implements ds.ReadWriteOrdCompBidRandCollIterator
func (*Iterator[T]) Next ¶
func (it *Iterator[T]) Next()
Next implements ds.ReadWriteOrdCompBidRandCollIterator
func (*Iterator[T]) NextN ¶ added in v0.11.0
NextN implements ds.ReadWriteOrdCompBidRandCollIterator
func (*Iterator[T]) Previous ¶ added in v0.11.0
func (it *Iterator[T]) Previous()
Previous implements ds.ReadWriteOrdCompBidRandCollIterator
func (*Iterator[T]) PreviousN ¶ added in v0.11.0
PreviousN implements ds.ReadWriteOrdCompBidRandCollIterator
type Stack ¶
type Stack[T any] struct { // contains filtered or unexported fields }
Stack holds elements in an array-list
func NewFromIterator ¶ added in v0.11.0
func NewFromIterator[T any](it ds.ReadCompForIterator[T]) *Stack[T]
NewFromIterator instantiates a new stack containing the elements provided by the passed iterator.
func NewFromIterators ¶ added in v0.11.0
func NewFromIterators[T any](first ds.ReadCompForIterator[T], end ds.ComparableIterator) *Stack[T]
NewFromIterators instantiates a new stack containing the elements provided by first, until it is equal to end. end is a sentinel and not included.
func NewFromSlice ¶ added in v0.11.0
NewFromSlice instantiates a new stack containing the provided slice.
func (*Stack[T]) Begin ¶ added in v0.11.0
func (set *Stack[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 (*Stack[T]) End ¶ added in v0.11.0
func (set *Stack[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 (*Stack[T]) First ¶ added in v0.11.0
func (set *Stack[T]) First() ds.ReadWriteOrdCompBidRandCollIterator[int, T]
First returns an initialized iterator, which points to it's first element.
func (*Stack[T]) GetValues ¶ added in v0.3.0
func (stack *Stack[T]) GetValues() []T
Values returns all elements in the stack (LIFO order).
func (*Stack[T]) IsEmpty ¶ added in v0.3.0
Empty returns true if stack does not contain any elements.
func (*Stack[T]) Last ¶ added in v0.11.0
func (set *Stack[T]) Last() ds.ReadWriteOrdCompBidRandCollIterator[int, T]
Last returns an initialized iterator, which points to it's last element.
func (*Stack[T]) MarshalJSON ¶
MarshalJSON @implements json.Marshaler
func (*Stack[T]) NewIterator ¶ added in v0.11.0
NewIterator returns a stateful iterator whose values can be fetched by an index.
func (*Stack[T]) Peek ¶
Peek returns top element on the stack without removing it, or nil if stack is empty. Second return parameter is true, unless the stack was empty and there was nothing to peek.
func (*Stack[T]) Pop ¶
Pop removes top element on stack and returns it, or nil if stack is empty. Second return parameter is true, unless the stack was empty and there was nothing to pop.
func (*Stack[T]) Push ¶
func (stack *Stack[T]) Push(value T)
Push adds a value onto the top of the stack
func (*Stack[T]) UnmarshalJSON ¶
UnmarshalJSON @implements json.Unmarshaler