list

package
v0.1.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListToMap

func ListToMap[T any, K comparable, V any](list *List[T], iteratee func(T) (K, V)) map[K]V

ListToMap convert a list to a map based on iteratee function.

Types

type CopyOnWriteList

type CopyOnWriteList[T any] struct {
	// contains filtered or unexported fields
}

func NewCopyOnWriteList

func NewCopyOnWriteList[T any](data []T) *CopyOnWriteList[T]

NewCopyOnWriteList Creates an empty list.

func (*CopyOnWriteList[T]) Add

func (c *CopyOnWriteList[T]) Add(e T) bool

Add appends the specified element to the end of this list.

func (*CopyOnWriteList[T]) AddAll

func (c *CopyOnWriteList[T]) AddAll(e []T) bool

AddAll appends all the elements in the specified collection to the end of this list

func (*CopyOnWriteList[T]) AddByIndex

func (c *CopyOnWriteList[T]) AddByIndex(index int, e T) bool

AddByIndex inserts the specified element at the specified position in this list.

func (*CopyOnWriteList[T]) Clear

func (c *CopyOnWriteList[T]) Clear()

Clear removes all the elements from this list.

func (*CopyOnWriteList[T]) Contain

func (c *CopyOnWriteList[T]) Contain(e T) bool

Contain returns true if this list contains the specified element.

func (*CopyOnWriteList[T]) DeleteAt

func (c *CopyOnWriteList[T]) DeleteAt(index int) (*T, bool)

DeleteAt removes the element at the specified position in this list.

func (*CopyOnWriteList[T]) DeleteBy

func (c *CopyOnWriteList[T]) DeleteBy(o T) (*T, bool)

DeleteBy removes the first occurrence of the specified element from this list, if it is present.

func (*CopyOnWriteList[T]) DeleteIf

func (c *CopyOnWriteList[T]) DeleteIf(f func(T) bool)

DeleteIf removes all the elements of this collection that satisfy the given predicate.

func (*CopyOnWriteList[T]) DeleteRange

func (c *CopyOnWriteList[T]) DeleteRange(start int, end int)

DeleteRange removes from this list all the elements whose index is between fromIndex, inclusive, and toIndex, exclusive. left close and right open

func (*CopyOnWriteList[T]) Equal

func (c *CopyOnWriteList[T]) Equal(other *[]T) bool

Equal returns true if the specified object is equal to this list.

func (*CopyOnWriteList[T]) ForEach

func (c *CopyOnWriteList[T]) ForEach(f func(T))

ForEach performs the given action for each element of the Iterable until all elements have been processed or the action throws an exception.

func (*CopyOnWriteList[T]) Get

func (c *CopyOnWriteList[T]) Get(index int) *T

Get returns the element at the specified position in this list.

func (*CopyOnWriteList[T]) IndexOf

func (c *CopyOnWriteList[T]) IndexOf(e T) int

IndexOf returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.

func (*CopyOnWriteList[T]) IsEmpty

func (c *CopyOnWriteList[T]) IsEmpty() bool

IsEmpty returns true if this list contains no elements.

func (*CopyOnWriteList[T]) LastIndexOf

func (c *CopyOnWriteList[T]) LastIndexOf(e T) int

LastIndexOf returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.

func (*CopyOnWriteList[T]) Merge

func (c *CopyOnWriteList[T]) Merge(other []T)

Merge a tow list to one, change the list

func (*CopyOnWriteList[T]) Set

func (c *CopyOnWriteList[T]) Set(index int, e T) (oldValue *T, ok bool)

Set replaces the element at the specified position in this list with the specified element.

func (*CopyOnWriteList[T]) Size

func (c *CopyOnWriteList[T]) Size() int

Size returns the number of elements in this list.

func (*CopyOnWriteList[T]) Sort

func (c *CopyOnWriteList[T]) Sort(compare func(o1 T, o2 T) bool)

Sort sorts this list according to the order induced by the specified Comparator.

func (*CopyOnWriteList[T]) SubList

func (c *CopyOnWriteList[T]) SubList(start int, end int) (newList []T)

func (*CopyOnWriteList[T]) ValueOf

func (c *CopyOnWriteList[T]) ValueOf(index int) (*T, bool)

ValueOf returns the index of the first occurrence of the specified element in this list, or null if this list does not contain the element.

type List

type List[T any] struct {
	// contains filtered or unexported fields
}

List is a linear table, implemented with slice.

func NewList

func NewList[T any](data []T) *List[T]

NewList return a pointer of List.

func (*List[T]) Cap

func (l *List[T]) Cap() int

Cap return cap of the inner data.

func (*List[T]) Clear

func (l *List[T]) Clear()

Clear the data of list.

func (*List[T]) Clone

func (l *List[T]) Clone() *List[T]

Clone return a copy of list.

func (*List[T]) Contain

func (l *List[T]) Contain(value T) bool

Contain checks if the value in the list or not.

func (*List[T]) Data

func (l *List[T]) Data() []T

Data return list data.

func (*List[T]) DeleteAll

func (l *List[T]) DeleteAll(list *List[T]) bool

DeleteAll removes from this list all of its elements that are contained in the given list.

func (*List[T]) DeleteAt

func (l *List[T]) DeleteAt(index int)

DeleteAt delete the value of list at index.

func (*List[T]) DeleteIf

func (l *List[T]) DeleteIf(f func(T) bool) int

DeleteIf delete all satisfying f(data[i]), returns count of removed elements

func (*List[T]) Difference

func (l *List[T]) Difference(other *List[T]) *List[T]

Difference returns the difference between two collections. return a list whose element in the original list, not in the given list.

func (*List[T]) Equal

func (l *List[T]) Equal(other *List[T]) bool

Equal compare list to other list, use reflect.DeepEqual.

func (*List[T]) ForEach

func (l *List[T]) ForEach(consumer func(T))

ForEach performs the given action for each element of the list.

func (*List[T]) IndexOf

func (l *List[T]) IndexOf(value T) int

IndexOf returns the index of value. if not found return -1.

func (*List[T]) IndexOfFunc

func (l *List[T]) IndexOfFunc(f func(T) bool) int

IndexOfFunc returns the first index satisfying f(v) if not found return -1.

func (*List[T]) InsertAt

func (l *List[T]) InsertAt(index int, value T)

InsertAt insert value into list at index.

func (*List[T]) InsertAtFirst

func (l *List[T]) InsertAtFirst(value T)

InsertAtFirst insert value into list at first index.

func (*List[T]) InsertAtLast

func (l *List[T]) InsertAtLast(value T)

InsertAtLast insert value into list at last index.

func (*List[T]) Intersection

func (l *List[T]) Intersection(other *List[T]) *List[T]

Intersection creates a new list whose element both be contained in list l and other.

func (*List[T]) IsEmpty

func (l *List[T]) IsEmpty() bool

IsEmpty check if the list is empty or not.

func (*List[T]) Iterator

func (l *List[T]) Iterator() iterator.Iterator[T]

Iterator returns an iterator over the elements in this list in proper sequence.

func (*List[T]) LastIndexOf

func (l *List[T]) LastIndexOf(value T) int

LastIndexOf returns the index of the last occurrence of the value in this list. if not found return -1.

func (*List[T]) LastIndexOfFunc

func (l *List[T]) LastIndexOfFunc(f func(T) bool) int

LastIndexOfFunc returns the index of the last occurrence of the value in this list satisfying f(data[i]) if not found return -1.

func (*List[T]) Merge

func (l *List[T]) Merge(other *List[T]) *List[T]

Merge two list, return new list, don't change original list.

func (*List[T]) PopFirst

func (l *List[T]) PopFirst() (*T, bool)

PopFirst delete the first value of list and return it.

func (*List[T]) PopLast

func (l *List[T]) PopLast() (*T, bool)

PopLast delete the last value of list and return it.

func (*List[T]) Push

func (l *List[T]) Push(value T)

Push append value to the list data.

func (*List[T]) RetainAll

func (l *List[T]) RetainAll(list *List[T]) bool

RetainAll retains only the elements in this list that are contained in the given list.

func (*List[T]) Reverse

func (l *List[T]) Reverse()

Reverse the item order of list.

func (*List[T]) Size

func (l *List[T]) Size() int

Size return number of list data items.

func (*List[T]) SubList

func (l *List[T]) SubList(fromIndex, toIndex int) *List[T]

SubList returns a sub list of the original list between the specified fromIndex, inclusive, and toIndex, exclusive.

func (*List[T]) Swap

func (l *List[T]) Swap(i, j int)

Swap the value of index i and j in list.

func (*List[T]) SymmetricDifference

func (l *List[T]) SymmetricDifference(other *List[T]) *List[T]

SymmetricDifference oppoiste operation of intersection function.

func (*List[T]) Union

func (l *List[T]) Union(other *List[T]) *List[T]

Union creates a new list contain all element in list l and other, delete duplicate element.

func (*List[T]) Unique

func (l *List[T]) Unique()

Unique delete duplicate items in list.

func (*List[T]) UpdateAt

func (l *List[T]) UpdateAt(index int, value T)

UpdateAt update value of list at index, index shoud between 0 and list size -1

func (*List[T]) ValueOf

func (l *List[T]) ValueOf(index int) (*T, bool)

ValueOf return the value pointer at index of list data.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL