Documentation
¶
Overview ¶
Package list provides common two-linked list with iterators
Can store any comparable value. No pointers and type-checks. Able to be used with 'range' and some functions of 'slices' package
Index ¶
- type List
- func (l *List[T]) Add(values ...T)
- func (l *List[T]) AddAfterIndex(index int, values ...T) bool
- func (l *List[T]) AddBeforeIndex(index int, values ...T) bool
- func (l *List[T]) Back() (val T, exists bool)
- func (l *List[LT]) Clear()
- func (l *List[T]) Clone() *List[T]
- func (l *List[T]) Contains(value T) bool
- func (l *List[T]) Delete(value T) bool
- func (l *List[T]) Equal(other *List[T]) bool
- func (l *List[T]) Find(value T) []int
- func (l *List[T]) Front() (val T, exists bool)
- func (l *List[T]) Index(value T) int
- func (l *List[LT]) Len() int
- func (l *List[T]) MoveAfter(from, to int) bool
- func (l *List[T]) MoveBefore(from, to int) bool
- func (l *List[LT]) PeakAt(index int) (val LT, exists bool)
- func (l *List[T]) PopAt(index int) (val T, exists bool)
- func (l *List[T]) PopBack() (val T, exists bool)
- func (l *List[T]) PopFront() (val T, exists bool)
- func (l *List[T]) PushBack(values ...T)
- func (l *List[T]) PushFront(values ...T)
- func (l *List[T]) RIndex(value T) int
- func (l *List[LT]) ReversedSeq() iter.Seq[LT]
- func (l *List[LT]) ReversedSeq2() iter.Seq2[int, LT]
- func (l *List[LT]) Seq() iter.Seq[LT]
- func (l *List[LT]) Seq2() iter.Seq2[int, LT]
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type List ¶
type List[LT comparable] struct { // contains filtered or unexported fields }
List Two-side linked list
func New ¶
func New[LT comparable](data ...LT) *List[LT]
New Create a new instance of List. Can be filled through initialization with direct order. l := New(1, 2, 3, 4, 5) returns List: 1 <-> 2 <-> 3 <-> 4 <-> 5
func (*List[T]) Add ¶
func (l *List[T]) Add(values ...T)
Add Add value to the end of the list. Same as PushBack.
func (*List[T]) AddAfterIndex ¶
AddAfterIndex Add value to the specific position. If list is 1 <-> 2 <-> 3 <-> 4 then you call this function with index 2 (for example with value 9). You will get 1 <-> 2 <-> 3 <-> 9 <-> 4
func (*List[T]) AddBeforeIndex ¶
AddBeforeIndex Add value to the specific position. If list is 1 <-> 2 <-> 3 <-> 4 then you call this function with index 2 (for example with value 9). You will get 1 <-> 2 <-> 9 <-> 3 <-> 4
func (*List[LT]) Clear ¶
func (l *List[LT]) Clear()
Clear Carefully remove all elements from the List. Prevent memory leaks and clear all links between elements. O(N)
func (*List[T]) Contains ¶
Contains returns true if list has at least one element. In other case returns false.
func (*List[T]) MoveBefore ¶
MoveBefore moves one element from the index 'from' before index 'to'.
func (*List[LT]) PeakAt ¶
PeakAt returns an element at the specific of the list and 'true'. If there is no element on this position the default value will be returned and 'false' as the second argument.
func (*List[T]) PopAt ¶
PopAt removes an element from the list and return them, the second argument will be 'true'. If there is no element on this position the default value will be returned and 'false' as the second argument.
func (*List[T]) PopBack ¶
PopBack removes the last element from the list and return them, the second argument will be 'true'. If there is no element default value will be returned and 'false' as the second argument.
func (*List[T]) PopFront ¶
PopFront removes the first element from the list and return them, the second argument will be 'true'. If there is no element default value will be returned and 'false' as the second argument.
func (*List[T]) PushBack ¶
func (l *List[T]) PushBack(values ...T)
PushBack Add value to the end of the list.
func (*List[T]) PushFront ¶
func (l *List[T]) PushFront(values ...T)
PushFront Add value to the start of the list.
func (*List[LT]) ReversedSeq ¶
ReversedSeq Return function for value-only sequence but reversed order. Can be used in slices library and range.
Example ¶
lst := New(1, 2, 3, 4)
for num := range lst.ReversedSeq() {
fmt.Println(num)
}
Output: 4 3 2 1
func (*List[LT]) ReversedSeq2 ¶
ReversedSeq2 Return function for int-value sequence (element number and value), but reversed order. Can be used in slices library and range.
Example ¶
lst := New(1, 2, 3, 4)
for i, num := range lst.ReversedSeq2() {
fmt.Printf("%d: %d\n", i, num)
}
fmt.Println()
// If you need indexes from 0 to 3
reverseIdx := func(seq2 iter.Seq2[int, int]) iter.Seq2[int, int] {
return func(yield func(int, int) bool) {
i := 0
for _, v := range seq2 {
if !yield(i, v) {
return
}
i++
}
}
}
for i, num := range reverseIdx(lst.ReversedSeq2()) {
fmt.Printf("%d: %d\n", i, num)
}
Output: 3: 4 2: 3 1: 2 0: 1 0: 4 1: 3 2: 2 3: 1
func (*List[LT]) Seq ¶
Seq Return function for value-only sequence. Can be used in slices library and range.
Example ¶
lst := New(1, 2, 3, 4)
for num := range lst.Seq() {
fmt.Println(num)
}
Output: 1 2 3 4