Documentation
¶
Overview ¶
Package sparse implements a special sparse array with popcount compression for max. 256 items.
Index ¶
- type Array256
- func (a *Array256[T]) Clear(uint)
- func (a *Array256[T]) Copy() *Array256[T]
- func (a *Array256[T]) DeleteAt(i uint8) (value T, exists bool)
- func (a *Array256[T]) Get(i uint8) (value T, ok bool)
- func (a *Array256[T]) InsertAt(i uint8, value T) (exists bool)
- func (a *Array256[T]) Len() int
- func (a *Array256[T]) MustGet(i uint8) T
- func (a *Array256[T]) Set(uint)
- func (a *Array256[T]) UpdateAt(i uint8, cb func(T, bool) T) (newValue T, wasPresent bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Array256 ¶
Array256 is a generic implementation of a sparse array with popcount compression for max. 256 items with payload T.
func (*Array256[T]) Clear ¶
Clear of the underlying bitset is forbidden. The bitset and the items are coupled. An unsynchronized Clear() disturbs the coupling between bitset and Items[].
func (*Array256[T]) Copy ¶
Copy returns a shallow copy of the Array. The elements are copied using assignment, this is no deep clone.
func (*Array256[T]) Get ¶
Get the value at i from sparse array.
example: a.Get(5) -> a.Items[1]
⬇
BitSet256: [0|0|1|0|0|1|0|...|1] <- 3 bits set
Items: [*|*|*] <- len(Items) = 3
⬆
BitSet256.Test(5): true
BitSet256.Rank(5): 2,
func (*Array256[T]) InsertAt ¶
InsertAt a value at i into the sparse array. If the value already exists, overwrite it with val and return true.
func (*Array256[T]) MustGet ¶
MustGet use it only after a successful test or the behavior is undefined, it will NOT PANIC.