buffer_list

package module
v0.0.0-...-860b20f Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2018 License: MPL-2.0 Imports: 5 Imported by: 0

README

buffer_list wercker status

Package is double linked list with (slice like) sequencial buffer.

container/list's value is not allocated sequncially. so element value occur fragmentation. buffer_list has []byte buffer in List.

buffer_list.List

buffer_list.List is double linked list with member data buffer. if you want to have buffer of list's value, you cant get effect its.

type Hoge struct {
  a int64
  b int64
  c *int64
}

buffer_list := buffer_list.New(&Hoge{}, 100)

hoge := buffer_list.Front().Value().(*Hoge)
hoge.a = 200
hoge.b = 500


new_e := blist.InsertLast() // allocate new element/value
hoge2 := new_e.Value().(*Hoge)
hoge2.a = 222
hoge2.b = 2222
hoge2.c = 1234
new_e.Commit() // protect from gc Free

for e:= blist.Front(); e != nil; e.Next() {
  fmt.Println("value", e.Value() )
}

buffer_list.AList

AList is 'alias list' of buffer_list.List. AList permit you to have multi list with shared buffer data. Alist has Genetator pattern.

bl :=  buffer_list.New(Hoge{}, 10000)
alist := Alist{parent: bl}
ae := alist.NewElem()
alist.Front().Insert(ae)
v := ae.Value().(*Hoge)
v.Commit()

// iteration
for e := range alist.Generator() {
     v := e.Value().(*Hoge)
}

WARNING

this packages buffer is []byte so pointer member of nested struct is commonly freed by GC. buffer_list implement to protect struct's pointer member. but this problem is not fully fixed.

if struct member is chan/slice/embedded pointer interface/Array/map/function/struct , protected.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/kazu/buffer_list

Documentation

Index

Constants

View Source
const (
	DEFAULT_BUF_SIZE = 1024
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AElement

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

AElement is an element of alias linked list.

func (*AElement) Base

func (e *AElement) Base() *Element

func (*AElement) Commit

func (ae *AElement) Commit()

register pointer protect GC

func (*AElement) Free

func (e *AElement) Free()

remove from alias list and free real list

func (*AElement) InitValue

func (ae *AElement) InitValue()

func (*AElement) Insert

func (at *AElement) Insert(e *AElement) *AElement

add elemnet after at_element

func (*AElement) List

func (e *AElement) List() *AList

func (*AElement) Next

func (e *AElement) Next() *AElement

Next return next list element or nil

func (*AElement) Prev

func (e *AElement) Prev() *AElement

Prev return previous list element or nil

func (*AElement) Remove

func (e *AElement) Remove() bool

remove element from alias list

func (*AElement) Value

func (ae *AElement) Value() interface{}

return value of reel element object

type AList

type AList struct {
	Len int
	// contains filtered or unexported fields
}

func NewAList

func NewAList(l *List) AList

func (*AList) Back

func (al *AList) Back() *AElement

last element of list

func (*AList) ElemByValue

func (l *AList) ElemByValue(v interface{}) *AElement

func (*AList) Front

func (al *AList) Front() *AElement

first element of list

func (*AList) Generator

func (l *AList) Generator() chan *AElement

func (*AList) NewElem

func (al *AList) NewElem() (ae *AElement)

func (*AList) Push

func (al *AList) Push(e *AElement) bool

add element to last of list

func (*AList) SizeOfParentCache

func (al *AList) SizeOfParentCache() int

type Element

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

func (*Element) Commit

func (e *Element) Commit()

func (*Element) DumpPicks

func (e *Element) DumpPicks() string

func (*Element) Free

func (e *Element) Free()

func (*Element) InitValue

func (e *Element) InitValue()

func (*Element) IsPicked

func (e *Element) IsPicked(i interface{}) bool

func (*Element) List

func (e *Element) List() *List

func (*Element) Next

func (e *Element) Next() *Element

func (*Element) Prev

func (e *Element) Prev() *Element

func (*Element) Value

func (e *Element) Value() interface{}

func (*Element) ValueWithCast

func (e *Element) ValueWithCast() interface{}

type List

type List struct {
	Used      *Element
	Freed     *Element
	SizeElm   int64
	SizeData  int64
	Used_idx  int64
	Value_inf interface{}

	Len int
	// contains filtered or unexported fields
}

func New

func New(first_value interface{}, buf_cnt int) (l *List)

func (*List) Back

func (l *List) Back() *Element

func (*List) Cap

func (l *List) Cap() int

func (*List) ElemByValue

func (l *List) ElemByValue(v interface{}) (elm *Element)

func (*List) Front

func (l *List) Front() *Element

func (*List) GetDataPtr

func (l *List) GetDataPtr() uintptr

func (*List) GetElement

func (l *List) GetElement() *Element

func (*List) Inf

func (l *List) Inf() interface{}

func (*List) Init

func (l *List) Init(first_value interface{}, value_len int) *List

func (*List) InsertLast

func (l *List) InsertLast() *Element

func (*List) InsertNewElem

func (l *List) InsertNewElem(at *Element) *Element

func (*List) Pick_ptr

func (l *List) Pick_ptr(e *Element)

func (*List) SetCastFunc

func (l *List) SetCastFunc(f func(val interface{}) interface{})

func (*List) TypeOfValue_inf

func (l *List) TypeOfValue_inf() reflect.Type

func (*List) Value

func (l *List) Value() interface{}

Jump to

Keyboard shortcuts

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