datastructure

package
v2.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2022 License: MIT Imports: 1 Imported by: 1

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

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

IndexOf reture the index of value. 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]) 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]) 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