Documentation ¶
Overview ¶
Package datastructure contains some data structure. list is a linear table, implemented with slice.
Index ¶
- func ListToMap[T any, K comparable, V any](list *List[T], iteratee func(T) (K, V)) map[K]V
- type CopyOnWriteList
- func (c *CopyOnWriteList[T]) Add(e T) bool
- func (c *CopyOnWriteList[T]) AddAll(e []T) bool
- func (c *CopyOnWriteList[T]) AddByIndex(index int, e T) bool
- func (c *CopyOnWriteList[T]) Clear()
- func (c *CopyOnWriteList[T]) Contain(e T) bool
- func (c *CopyOnWriteList[T]) DeleteAt(index int) (*T, bool)
- func (c *CopyOnWriteList[T]) DeleteBy(o T) (*T, bool)
- func (c *CopyOnWriteList[T]) DeleteIf(f func(T) bool)
- func (c *CopyOnWriteList[T]) DeleteRange(start int, end int)
- func (c *CopyOnWriteList[T]) Equal(other *[]T) bool
- func (c *CopyOnWriteList[T]) ForEach(f func(T))
- func (c *CopyOnWriteList[T]) Get(index int) *T
- func (c *CopyOnWriteList[T]) IndexOf(e T) int
- func (l *CopyOnWriteList[T]) IndexOfFunc(f func(T) bool) int
- func (c *CopyOnWriteList[T]) IsEmpty() bool
- func (c *CopyOnWriteList[T]) LastIndexOf(e T) int
- func (l *CopyOnWriteList[T]) LastIndexOfFunc(f func(T) bool) int
- func (c *CopyOnWriteList[T]) Merge(other []T)
- func (c *CopyOnWriteList[T]) Set(index int, e T) (oldValue *T, ok bool)
- func (c *CopyOnWriteList[T]) Size() int
- func (c *CopyOnWriteList[T]) Sort(compare func(o1 T, o2 T) bool)
- func (c *CopyOnWriteList[T]) SubList(start int, end int) (newList []T)
- func (c *CopyOnWriteList[T]) ValueOf(index int) (*T, bool)
- type List
- func (l *List[T]) Cap() int
- func (l *List[T]) Clear()
- func (l *List[T]) Clone() *List[T]
- func (l *List[T]) Contain(value T) bool
- func (l *List[T]) Data() []T
- func (l *List[T]) DeleteAll(list *List[T]) bool
- func (l *List[T]) DeleteAt(index int)
- func (l *List[T]) DeleteIf(f func(T) bool) int
- func (l *List[T]) Difference(other *List[T]) *List[T]
- func (l *List[T]) Equal(other *List[T]) bool
- func (l *List[T]) ForEach(consumer func(T))
- func (l *List[T]) IndexOf(value T) int
- func (l *List[T]) IndexOfFunc(f func(T) bool) int
- func (l *List[T]) InsertAt(index int, value T)
- func (l *List[T]) InsertAtFirst(value T)
- func (l *List[T]) InsertAtLast(value T)
- func (l *List[T]) Intersection(other *List[T]) *List[T]
- func (l *List[T]) IsEmpty() bool
- func (l *List[T]) Iterator() iterator.Iterator[T]
- func (l *List[T]) LastIndexOf(value T) int
- func (l *List[T]) LastIndexOfFunc(f func(T) bool) int
- func (l *List[T]) Merge(other *List[T]) *List[T]
- func (l *List[T]) PopFirst() (*T, bool)
- func (l *List[T]) PopLast() (*T, bool)
- func (l *List[T]) Push(value T)
- func (l *List[T]) RetainAll(list *List[T]) bool
- func (l *List[T]) Reverse()
- func (l *List[T]) Size() int
- func (l *List[T]) SubList(fromIndex, toIndex int) *List[T]
- func (l *List[T]) Swap(i, j int)
- func (l *List[T]) SymmetricDifference(other *List[T]) *List[T]
- func (l *List[T]) Union(other *List[T]) *List[T]
- func (l *List[T]) Unique()
- func (l *List[T]) UpdateAt(index int, value T)
- func (l *List[T]) ValueOf(index int) (*T, bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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]) IndexOfFunc ¶
func (l *CopyOnWriteList[T]) IndexOfFunc(f func(T) bool) int
IndexOfFunc returns the first index satisfying the functional predicate f(v) bool if not found return -1.
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]) LastIndexOfFunc ¶
func (l *CopyOnWriteList[T]) LastIndexOfFunc(f func(T) bool) int
LastIndexOfFunc returns the index of the last occurrence of the value in this list satisfying the functional predicate f(T) bool if not found return -1.
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 (*List[T]) DeleteAll ¶
DeleteAll removes from this list all of its elements that are contained in the given list.
func (*List[T]) DeleteIf ¶
DeleteIf delete all satisfying f(data[i]), returns count of removed elements
func (*List[T]) Difference ¶
Difference returns the difference between two collections. return a list whose element in the original list, not in the given list.
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]) IndexOfFunc ¶
IndexOfFunc returns the first index satisfying f(v) if not found return -1.
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 ¶
Intersection creates a new list whose element both be contained in list l and other.
func (*List[T]) Iterator ¶
Iterator returns an iterator over the elements in this list in proper sequence.
func (*List[T]) LastIndexOf ¶
LastIndexOf returns the index of the last occurrence of the value in this list. if not found return -1.
func (*List[T]) LastIndexOfFunc ¶
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]) RetainAll ¶
RetainAll retains only the elements in this list that are contained in the given list.
func (*List[T]) SubList ¶
SubList returns a sub list of the original list between the specified fromIndex, inclusive, and toIndex, exclusive.
func (*List[T]) SymmetricDifference ¶
SymmetricDifference oppoiste operation of intersection function.
func (*List[T]) Union ¶
Union creates a new list contain all element in list l and other, delete duplicate element.