datastructure

package
v2.2.4 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2023 License: MIT Imports: 2 Imported by: 1

Documentation

Overview

Package datastructure contains some data structure. list is a linear table, implemented with slice.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListToMap added in v2.1.14

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 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 added in v2.1.4

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 added in v2.1.14

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 added in v2.1.4

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 added in v2.1.14

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 added in v2.0.8

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

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

func (*List[T]) ForEach added in v2.1.14

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 added in v2.1.4

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 added in v2.1.14

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 added in v2.1.4

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 added in v2.1.4

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 added in v2.1.14

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 added in v2.1.4

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 added in v2.1.14

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, remove duplicate element.

func (*List[T]) Unique

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

Unique remove 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