list

package
v1.2.9 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2023 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Consumer added in v1.2.9

type Consumer func(i int, v interface{}) bool

Consumer traverses list. It receives index and value as params, returns true to continue traversal, while returns false to break

type Expected added in v1.2.9

type Expected func(a interface{}) bool

Expected check whether given item is equals to expected value

type LinkedList

type LinkedList struct {
	// contains filtered or unexported fields
}

LinkedList is doubly linked list

func Make

func Make(vals ...interface{}) *LinkedList

Make creates a new linked list

func (*LinkedList) Add

func (list *LinkedList) Add(val interface{})

Add adds value to the tail

func (*LinkedList) Contains

func (list *LinkedList) Contains(expected Expected) bool

Contains returns whether the given value exist in the list

func (*LinkedList) ForEach

func (list *LinkedList) ForEach(consumer Consumer)

ForEach visits each element in the list if the consumer returns false, the loop will be break

func (*LinkedList) Get

func (list *LinkedList) Get(index int) (val interface{})

Get returns value at the given index

func (*LinkedList) Insert

func (list *LinkedList) Insert(index int, val interface{})

Insert inserts value at the given index, the original element at the given index will move backward

func (*LinkedList) Len

func (list *LinkedList) Len() int

Len returns the number of elements in list

func (*LinkedList) Range

func (list *LinkedList) Range(start int, stop int) []interface{}

Range returns elements which index within [start, stop)

func (*LinkedList) Remove

func (list *LinkedList) Remove(index int) (val interface{})

Remove removes value at the given index

func (*LinkedList) RemoveAllByVal

func (list *LinkedList) RemoveAllByVal(expected Expected) int

RemoveAllByVal removes all elements with the given val

func (*LinkedList) RemoveByVal

func (list *LinkedList) RemoveByVal(expected Expected, count int) int

RemoveByVal removes at most `count` values of the specified value in this list scan from left to right

func (*LinkedList) RemoveLast

func (list *LinkedList) RemoveLast() (val interface{})

RemoveLast removes the last element and returns its value

func (*LinkedList) ReverseRemoveByVal

func (list *LinkedList) ReverseRemoveByVal(expected Expected, count int) int

ReverseRemoveByVal removes at most `count` values of the specified value in this list scan from right to left

func (*LinkedList) Set

func (list *LinkedList) Set(index int, val interface{})

Set updates value at the given index, the index should between [0, list.size]

type List added in v1.2.9

type List interface {
	Add(val interface{})
	Get(index int) (val interface{})
	Set(index int, val interface{})
	Insert(index int, val interface{})
	Remove(index int) (val interface{})
	RemoveLast() (val interface{})
	RemoveAllByVal(expected Expected) int
	RemoveByVal(expected Expected, count int) int
	ReverseRemoveByVal(expected Expected, count int) int
	Len() int
	ForEach(consumer Consumer)
	Contains(expected Expected) bool
	Range(start int, stop int) []interface{}
}

type QuickList added in v1.2.9

type QuickList struct {
	// contains filtered or unexported fields
}

QuickList is a linked list of page (which type is []interface{}) QuickList has better performance than LinkedList of Add, Range and memory usage

func NewQuickList added in v1.2.9

func NewQuickList() *QuickList

func (*QuickList) Add added in v1.2.9

func (ql *QuickList) Add(val interface{})

Add adds value to the tail

func (*QuickList) Contains added in v1.2.9

func (ql *QuickList) Contains(expected Expected) bool

func (*QuickList) ForEach added in v1.2.9

func (ql *QuickList) ForEach(consumer Consumer)

ForEach visits each element in the list if the consumer returns false, the loop will be break

func (*QuickList) Get added in v1.2.9

func (ql *QuickList) Get(index int) (val interface{})

Get returns value at the given index

func (*QuickList) Insert added in v1.2.9

func (ql *QuickList) Insert(index int, val interface{})

func (*QuickList) Len added in v1.2.9

func (ql *QuickList) Len() int

Len returns the number of elements in list

func (*QuickList) Range added in v1.2.9

func (ql *QuickList) Range(start int, stop int) []interface{}

Range returns elements which index within [start, stop)

func (*QuickList) Remove added in v1.2.9

func (ql *QuickList) Remove(index int) interface{}

Remove removes value at the given index

func (*QuickList) RemoveAllByVal added in v1.2.9

func (ql *QuickList) RemoveAllByVal(expected Expected) int

RemoveAllByVal removes all elements with the given val

func (*QuickList) RemoveByVal added in v1.2.9

func (ql *QuickList) RemoveByVal(expected Expected, count int) int

RemoveByVal removes at most `count` values of the specified value in this list scan from left to right

func (*QuickList) RemoveLast added in v1.2.9

func (ql *QuickList) RemoveLast() interface{}

RemoveLast removes the last element and returns its value

func (*QuickList) ReverseRemoveByVal added in v1.2.9

func (ql *QuickList) ReverseRemoveByVal(expected Expected, count int) int

func (*QuickList) Set added in v1.2.9

func (ql *QuickList) Set(index int, val interface{})

Set updates value at the given index, the index should between [0, list.size]

Jump to

Keyboard shortcuts

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