Documentation
¶
Overview ¶
Package doublylinkedlist implements the doubly-linked list.
Structure is not thread safe.
Reference: https://en.wikipedia.org/wiki/List[T]_%28abstract_data_type%29
Index ¶
- type Iterator
- func (iterator *Iterator) Begin()
- func (iterator *Iterator) End()
- func (iterator *Iterator) First() bool
- func (iterator *Iterator) Index() int
- func (iterator *Iterator) Last() bool
- func (iterator *Iterator) Next() bool
- func (iterator *Iterator) NextTo(f func(index int, value interface{}) bool) bool
- func (iterator *Iterator) Prev() bool
- func (iterator *Iterator) PrevTo(f func(index int, value interface{}) bool) bool
- func (iterator *Iterator) Value() interface{}
- type List
- func (list *List[T]) Add(values ...T)
- 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) Iterator() Iterator
- func (list *List[T]) MarshalJSON() ([]byte, error)
- func (list *List[T]) PopBack()
- func (list *List[T]) PopFront()
- func (list *List[T]) Prepend(values ...T)
- 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 struct {
// contains filtered or unexported fields
}
Iterator holding the iterator's state
func (*Iterator) Begin ¶
func (iterator *Iterator) Begin()
Begin resets the iterator to its initial state (one-before-first) Call Next() to fetch the first element if any.
func (*Iterator) End ¶
func (iterator *Iterator) End()
End moves the iterator past the last element (one-past-the-end). Call Prev() to fetch the last element if any.
func (*Iterator) 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) Index ¶
Index returns the current element's index. Does not modify the state of the iterator.
func (*Iterator) 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) 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) 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) 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) 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 any] struct { // contains filtered or unexported fields }
List[T] holds the elements, where each element points to the next and previous element
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]) 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 ¶
func (list *List[T]) Contains(comparator utils.Comparator[T], values ...T) bool
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]) 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) 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]) Prepend ¶
func (list *List[T]) Prepend(values ...T)
Prepend prepends a values (or more)
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