datastructure

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2023 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package datastructure implements some data structure. eg. list, linklist, stack, queue, tree, graph.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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

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]) 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]) Equal

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

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

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]) 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]) 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]) 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