Documentation ¶
Overview ¶
Package doublylinkedlist implements the doubly-linked list.
Structure is not thread safe.
Reference: https://en.wikipedia.org/wiki/List_%28abstract_data_type%29
Index ¶
- type Iterator
- func (iterator *Iterator[T]) Begin()
- func (iterator *Iterator[T]) End()
- func (iterator *Iterator[T]) First() bool
- func (iterator *Iterator[T]) Index() int
- func (iterator *Iterator[T]) Last() bool
- func (iterator *Iterator[T]) Next() bool
- func (iterator *Iterator[T]) NextTo(f func(index int, value T) bool) bool
- func (iterator *Iterator[T]) Prev() bool
- func (iterator *Iterator[T]) PrevTo(f func(index int, value T) bool) bool
- func (iterator *Iterator[T]) Value() T
- type List
- func (list *List[T]) Add(values ...T)
- func (list *List[T]) All(f func(index int, value T) bool) bool
- func (list *List[T]) Any(f func(index int, value T) bool) bool
- func (list *List[T]) Append(values ...T)
- func (list *List[T]) Clear()
- func (list *List[T]) Contains(values ...T) bool
- func (list *List[T]) Each(f func(index int, value T))
- func (list *List[T]) Empty() bool
- func (list *List[T]) Find(f func(index int, value T) bool) (index int, value T)
- func (list *List[T]) FromJSON(data []byte) error
- func (list *List[T]) Get(index int) (T, bool)
- func (list *List[T]) IndexOf(value T) int
- func (list *List[T]) Insert(index int, values ...T)
- func (list *List[T]) Iterator() Iterator[T]
- func (list *List[T]) Map(f func(index int, value T) T) *List[T]
- func (list *List[T]) MarshalJSON() ([]byte, error)
- func (list *List[T]) Prepend(values ...T)
- func (list *List[T]) Remove(index int)
- func (list *List[T]) Select(f func(index int, value T) bool) *List[T]
- 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]) String() string
- func (list *List[T]) Swap(i, j int)
- func (list *List[T]) ToJSON() ([]byte, error)
- func (list *List[T]) UnmarshalJSON(bytes []byte) error
- func (list *List[T]) Values() []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Iterator ¶
type Iterator[T comparable] 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]) End ¶
func (iterator *Iterator[T]) End()
End moves the iterator past the last element (one-past-the-end). Call Prev() to fetch the last 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]) Last ¶
Last moves the iterator to the last element and returns true if there was a last element in the container. If Last() returns true, then last element's index and value can be retrieved by Index() and Value(). Modifies 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.
func (*Iterator[T]) Prev ¶
Prev moves the iterator to the previous element and returns true if there was a previous element in the container. If Prev() returns true, then previous element's index and value can be retrieved by Index() and Value(). Modifies the state of the iterator.
func (*Iterator[T]) PrevTo ¶
PrevTo moves the iterator to the previous 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 PrevTo() 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 comparable] struct { // contains filtered or unexported fields }
List holds the elements, where each element points to the next and previous element
func New ¶
func New[T comparable](values ...T) *List[T]
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 (one or more) at the end of the list (same as Append())
func (*List[T]) All ¶
All passes each element of the container to the given function and returns true if the function returns true for all elements.
func (*List[T]) Any ¶
Any passes each element of the container to the given function and returns true if the function ever returns true for any 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 Add())
func (*List[T]) Contains ¶
Contains check 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]) Each ¶
Each calls the given function once for each element, passing that element's index and value.
func (*List[T]) Find ¶
Find passes each element of the container to the given function and returns the first (index,value) for which the function is true or -1,nil otherwise if no element matches the criteria.
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]) 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]) Map ¶
Map invokes the given function once for each element and returns a container containing the values returned by the given function.
func (*List[T]) MarshalJSON ¶
MarshalJSON @implements json.Marshaler
func (*List[T]) Prepend ¶
func (list *List[T]) Prepend(values ...T)
Prepend prepends a values (or more)
func (*List[T]) Select ¶
Select returns a new container containing all elements for which the given function returns a true value.
func (*List[T]) Set ¶
Set value at specified index position 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 sorts values (in-place) using.
func (*List[T]) UnmarshalJSON ¶
UnmarshalJSON @implements json.Unmarshaler