Documentation ¶
Index ¶
- type Consumer
- type Expected
- type LinkedList
- func (list *LinkedList) Add(val interface{})
- func (list *LinkedList) Contains(expected Expected) bool
- func (list *LinkedList) ForEach(consumer Consumer)
- func (list *LinkedList) Get(index int) (val interface{})
- func (list *LinkedList) Insert(index int, val interface{})
- func (list *LinkedList) Len() int
- func (list *LinkedList) Range(start int, stop int) []interface{}
- func (list *LinkedList) Remove(index int) (val interface{})
- func (list *LinkedList) RemoveAllByVal(expected Expected) int
- func (list *LinkedList) RemoveByVal(expected Expected, count int) int
- func (list *LinkedList) RemoveLast() (val interface{})
- func (list *LinkedList) ReverseRemoveByVal(expected Expected, count int) int
- func (list *LinkedList) Set(index int, val interface{})
- type List
- type QuickList
- func (ql *QuickList) Add(val interface{})
- func (ql *QuickList) Contains(expected Expected) bool
- func (ql *QuickList) ForEach(consumer Consumer)
- func (ql *QuickList) Get(index int) (val interface{})
- func (ql *QuickList) Insert(index int, val interface{})
- func (ql *QuickList) Len() int
- func (ql *QuickList) Range(start int, stop int) []interface{}
- func (ql *QuickList) Remove(index int) interface{}
- func (ql *QuickList) RemoveAllByVal(expected Expected) int
- func (ql *QuickList) RemoveByVal(expected Expected, count int) int
- func (ql *QuickList) RemoveLast() interface{}
- func (ql *QuickList) ReverseRemoveByVal(expected Expected, count int) int
- func (ql *QuickList) Set(index int, val interface{})
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Consumer ¶
Consumer traverses list. It receives index and value as params, returns true to continue traversal, while returns false to break
type Expected ¶
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 (*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 ¶
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 ¶
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 ¶
func NewQuickList() *QuickList
func (*QuickList) ForEach ¶
ForEach visits each element in the list if the consumer returns false, the loop will be break
func (*QuickList) RemoveAllByVal ¶
RemoveAllByVal removes all elements with the given val
func (*QuickList) RemoveByVal ¶
RemoveByVal removes at most `count` values of the specified value in this list scan from left to right
func (*QuickList) RemoveLast ¶
func (ql *QuickList) RemoveLast() interface{}
RemoveLast removes the last element and returns its value