Documentation ¶
Index ¶
- type Element
- type List
- func (that *List) Back() (e *Element)
- func (that *List) BackAll() (values []interface{})
- func (that *List) BackValue() (value interface{})
- func (that *List) Clear()
- func (that *List) Front() (e *Element)
- func (that *List) FrontAll() (values []interface{})
- func (that *List) FrontValue() (value interface{})
- func (that *List) InsertAfter(p *Element, v interface{}) (e *Element)
- func (that *List) InsertBefore(p *Element, v interface{}) (e *Element)
- func (that *List) Iterator(f func(e *Element) bool)
- func (that *List) IteratorAsc(f func(e *Element) bool)
- func (that *List) IteratorDesc(f func(e *Element) bool)
- func (that *List) Join(glue string) string
- func (that *List) Len() (length int)
- func (that *List) LockFunc(f func(list *list.List))
- func (that *List) MarshalJSON() ([]byte, error)
- func (that *List) MoveAfter(e, p *Element)
- func (that *List) MoveBefore(e, p *Element)
- func (that *List) MoveToBack(e *Element)
- func (that *List) MoveToFront(e *Element)
- func (that *List) PopBack() interface{}
- func (that *List) PopBackAll() []interface{}
- func (that *List) PopBacks(max int) (values []interface{})
- func (that *List) PopFront() interface{}
- func (that *List) PopFrontAll() []interface{}
- func (that *List) PopFronts(max int) (values []interface{})
- func (that *List) PushBack(v interface{}) *Element
- func (that *List) PushBackList(other *List)
- func (that *List) PushBacks(values []interface{})
- func (that *List) PushFront(v interface{}) *Element
- func (that *List) PushFrontList(other *List)
- func (that *List) PushFronts(values []interface{})
- func (that *List) RLockFunc(f func(list *list.List))
- func (that *List) Remove(e *Element) (value interface{})
- func (that *List) RemoveAll()
- func (that *List) Removes(es []*Element)
- func (that *List) Size() int
- func (that *List) String() string
- func (that *List) UnmarshalJSON(b []byte) error
- func (that *List) UnmarshalValue(value interface{}) (err error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type List ¶
type List struct {
// contains filtered or unexported fields
}
List 是一个包含并发安全开关的双向链表,开关在对象创建的时候确认,并且不能更改。
func New ¶
New 创建
Example ¶
package main import ( "fmt" "github.com/osgochina/donkeygo/container/dlist" ) func main() { n := 10 l := dlist.New() for i := 0; i < n; i++ { l.PushBack(i) } fmt.Println(l.Len()) fmt.Println(l.FrontAll()) fmt.Println(l.BackAll()) for i := 0; i < n; i++ { fmt.Print(l.PopFront()) } l.Clear() fmt.Println() fmt.Println(l.Len()) }
Output: 10 [0 1 2 3 4 5 6 7 8 9] [9 8 7 6 5 4 3 2 1 0] 0123456789 0
func (*List) InsertAfter ¶
InsertAfter 插入值v到节点p的后面,并返回该节点
func (*List) InsertBefore ¶
InsertBefore 插入值v到节点p的前面,并返回该节点
func (*List) IteratorAsc ¶
IteratorAsc 从头开始迭代
Example ¶
package main import ( "fmt" "github.com/osgochina/donkeygo/container/darray" "github.com/osgochina/donkeygo/container/dlist" ) func main() { // concurrent-safe list. l := dlist.NewFrom(darray.NewArrayRange(1, 10, 1).Slice(), true) // iterate reading from head using IteratorAsc. l.IteratorAsc(func(e *dlist.Element) bool { fmt.Print(e.Value) return true }) }
Output: 12345678910
func (*List) IteratorDesc ¶
IteratorDesc 从尾部开始迭代
Example ¶
package main import ( "fmt" "github.com/osgochina/donkeygo/container/darray" "github.com/osgochina/donkeygo/container/dlist" ) func main() { // concurrent-safe list. l := dlist.NewFrom(darray.NewArrayRange(1, 10, 1).Slice(), true) // iterate reading from tail using IteratorDesc. l.IteratorDesc(func(e *dlist.Element) bool { fmt.Print(e.Value) return true }) }
Output: 10987654321
func (*List) Join ¶
Join 把链表中的值,按glue分隔符链接起来
Example ¶
package main import ( "fmt" "github.com/osgochina/donkeygo/container/dlist" "github.com/osgochina/donkeygo/frame/d" ) func main() { var l dlist.List l.PushBacks(d.Slice{"a", "b", "c", "d"}) fmt.Println(l.Join(",")) }
Output: a,b,c,d
func (*List) LockFunc ¶
LockFunc 加读写锁执行函数
Example ¶
package main import ( "container/list" "fmt" "github.com/osgochina/donkeygo/container/darray" "github.com/osgochina/donkeygo/container/dlist" ) func main() { // concurrent-safe list. l := dlist.NewFrom(darray.NewArrayRange(1, 10, 1).Slice(), true) // iterate writing from head. l.LockFunc(func(list *list.List) { length := list.Len() if length > 0 { for i, e := 0, list.Front(); i < length; i, e = i+1, e.Next() { if e.Value == 6 { e.Value = "M" break } } } }) fmt.Println(l) }
Output: [1,2,3,4,5,M,7,8,9,10]
func (*List) PopBack ¶
func (that *List) PopBack() interface{}
PopBack 获取链表的尾节点的值,并且移除该节点
Example ¶
package main import ( "fmt" "github.com/osgochina/donkeygo/container/dlist" "github.com/osgochina/donkeygo/frame/d" ) func main() { l := dlist.NewFrom(d.Slice{1, 2, 3, 4, 5, 6, 7, 8, 9}) fmt.Println(l.PopBack()) }
Output: 9
func (*List) PopBacks ¶
PopBacks 取出链表尾部最多max个节点的值
Example ¶
package main import ( "fmt" "github.com/osgochina/donkeygo/container/dlist" "github.com/osgochina/donkeygo/frame/d" ) func main() { l := dlist.NewFrom(d.Slice{1, 2, 3, 4, 5, 6, 7, 8, 9}) fmt.Println(l.PopBacks(2)) }
Output: [9 8]
func (*List) PopFront ¶
func (that *List) PopFront() interface{}
PopFront 获取链表的头节点的值,并且移除该节点
Example ¶
package main import ( "fmt" "github.com/osgochina/donkeygo/container/dlist" "github.com/osgochina/donkeygo/frame/d" ) func main() { l := dlist.NewFrom(d.Slice{1, 2, 3, 4, 5, 6, 7, 8, 9}) fmt.Println(l.PopFront()) }
Output: 1
func (*List) PopFrontAll ¶
func (that *List) PopFrontAll() []interface{}
PopFrontAll 从链表头部开始取,取出全部的值
func (*List) PopFronts ¶
PopFronts 取出链表头部最多max个节点的值
Example ¶
package main import ( "fmt" "github.com/osgochina/donkeygo/container/dlist" "github.com/osgochina/donkeygo/frame/d" ) func main() { l := dlist.NewFrom(d.Slice{1, 2, 3, 4, 5, 6, 7, 8, 9}) fmt.Println(l.PopFronts(2)) }
Output: [1 2]
func (*List) PushBackList ¶
PushBackList 把链表other链接到链表的尾部
func (*List) PushFrontList ¶
PushFrontList 把链表other链接到链表的头部
func (*List) RLockFunc ¶
RLockFunc 加读锁执行函数
Example ¶
package main import ( "container/list" "fmt" "github.com/osgochina/donkeygo/container/darray" "github.com/osgochina/donkeygo/container/dlist" ) func main() { // concurrent-safe list. l := dlist.NewFrom(darray.NewArrayRange(1, 10, 1).Slice(), true) // iterate reading from head. l.RLockFunc(func(list *list.List) { length := list.Len() if length > 0 { for i, e := 0, list.Front(); i < length; i, e = i+1, e.Next() { fmt.Print(e.Value) } } }) fmt.Println() // iterate reading from tail. l.RLockFunc(func(list *list.List) { length := list.Len() if length > 0 { for i, e := 0, list.Back(); i < length; i, e = i+1, e.Prev() { fmt.Print(e.Value) } } }) fmt.Println() }
Output: 12345678910 10987654321
func (*List) UnmarshalJSON ¶
UnmarshalJSON 把json串反序列化成链表
func (*List) UnmarshalValue ¶
UnmarshalValue 解码内容
Click to show internal directories.
Click to hide internal directories.