Documentation ¶
Overview ¶
Package sparse provides the creation of sparse.Slice via sparse.NewSlice
Sparse items are design to automatically grow and reuse memory so they try to minimize the GC pauses
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrItemNotFound is the error when we could not find an item ErrItemNotFound = errors.New("item not found") )
Functions ¶
This section is empty.
Types ¶
type Iterator ¶
type Iterator interface { // Next returns the next element, nil if we haven't got more Next() Iterator // Value returns the current item value Value() interface{} }
Iterator allows to move trough the items in sparse with a for-loop
type Slice ¶
type Slice interface { // Add a new item to the slice Add(ref interface{}) // Remove a item in the slice Remove(ref interface{}) error // Clear al the items in the slice Clear() // Size return the number of items in this slice Size() int // Iterator returns a new sparse.Iterator for sparse.Slice Iterator() Iterator // AssureCapacity grows the Slice until it has at least the desired capacity AssureCapacity(capacity int) // Sort a sparse.Slice in-place using a less function Sort(less func(a interface{}, b interface{}) bool) // Copy makes a copy of this Slice into dest Copy(dest Slice) // Replace replace dest contents with this Slice contents Replace(dest Slice) }
Slice is an slice that contains interfaces, we need to specify a initial capacity
When remove at item it marked as free so the next added item will reuse the free slot ¶
Is dynamically sized, so first grow will double it current capacity, consecutive grows will be 25% of the current capacity
The implementation use go standard slices so when grow it probably do not need to be reallocated
Click to show internal directories.
Click to hide internal directories.