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 ¶
- type Iterator
- type List
- func (list *List[T]) Append(values ...T)
- func (list *List[T]) Clear()
- func (list *List[T]) Contains(comparator utils.Comparator[T], values ...T) bool
- func (list *List[T]) FromJSON(data []byte) error
- func (list *List[T]) Get(index int) (value T, found bool)
- 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]) Iterator() Iterator[T]
- func (list *List[T]) MarshalJSON() ([]byte, error)
- 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]) Set(index int, value T)
- 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]) 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]) Begin ¶
func (iterator *Iterator[T]) Begin()
Begin resets the iterator to its initial state (one-before-first) Call Next() to fetch the first element if any.
func (*Iterator[T]) First ¶
First moves the iterator to the first element and returns true if there was a first element in the container. If First() returns true, then first element's index and value can be retrieved by Index() and Value(). Modifies the state of the iterator.
func (*Iterator[T]) Index ¶
Index returns the current element's index. Does not modify the state of the iterator.
func (*Iterator[T]) Next ¶
Next moves the iterator to the next element and returns true if there was a next element in the container. If Next() returns true, then next element's index and value can be retrieved by Index() and Value(). If Next() was called for the first time, then it will point the iterator to the first element if it exists. Modifies the state of the iterator.
func (*Iterator[T]) NextTo ¶
NextTo moves the iterator to the next element from current position that satisfies the condition given by the passed function, and returns true if there was a next element in the container. If NextTo() returns true, then next element's index and value can be retrieved by Index() and Value(). Modifies the state of the iterator.
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 (*List[T]) Append ¶
func (list *List[T]) Append(values ...T)
Append appends a value (one or more) at the end of the list (same as PushBack())
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]) 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]) 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 ¶
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]) Iterator ¶
Iterator returns a stateful iterator whose values can be fetched by an index.
func (*List[T]) MarshalJSON ¶
MarshalJSON @implements json.Marshaler
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]) Set ¶
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]) Sort ¶
func (list *List[T]) Sort(comparator utils.Comparator[T])
Sort sort values (in-place) using.
func (*List[T]) UnmarshalJSON ¶
UnmarshalJSON @implements json.Unmarshaler