Documentation ¶
Overview ¶
Package bitmap implements (thread-safe) bitmap functions and abstractions.
Installation
go get github.com/boljen/go-bitmap
Index ¶
- func Get(m []byte, i int) bool
- func GetAtomicUint32(bitmap []uint32, targetBit int) bool
- func GetBit(b byte, i int) bool
- func Len(m []byte) int
- func NewSlice(l int) []byte
- func Set(m []byte, i int, v bool)
- func SetAtomic(bitmap []byte, targetBit int, targetValue bool)
- func SetAtomicUint32(bitmap []uint32, targetBit int, targetValue bool)
- func SetBit(b byte, i int, v bool) byte
- func SetBitRef(b *byte, i int, v bool)
- type Bitmap
- type Concurrent
- type Threadsafe
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetAtomicUint32 ¶
GetAtomicUint32 gets the target bit from an uint32 encoded bitmap.
func Len ¶
Len returns the length (in bits) of the provided byteslice. It will always be a multipile of 8 bits.
func NewSlice ¶
NewSlice creates a new byteslice with length l (in bits). The actual size in bits might be up to 7 bits larger because they are stored in a byteslice.
func SetAtomicUint32 ¶
SetAtomicUint32 sets the target bit to the target value inside the uint32 encded bitmap.
Types ¶
type Bitmap ¶
type Bitmap []byte
Bitmap is a byteslice with bitmap functions. Creating one form existing data is as simple as bitmap := Bitmap(data).
type Concurrent ¶
type Concurrent []byte
Concurrent is a bitmap implementation that achieves thread-safety using atomic operations along with some unsafe. It performs atomic operations on 32bits of data.
func NewConcurrent ¶
func NewConcurrent(l int) Concurrent
NewConcurrent returns a concurrent bitmap. It will create a bitmap
func (Concurrent) Data ¶
func (c Concurrent) Data(copy bool) []byte
Data returns the data of the bitmap. If copy is false the actual underlying slice will be returned.
func (Concurrent) Set ¶
func (c Concurrent) Set(b int, v bool)
Set wraps around the SetAtomic function.
type Threadsafe ¶
type Threadsafe struct {
// contains filtered or unexported fields
}
Threadsafe implements thread-safe read- and write locking for the bitmap.
func TSFromData ¶
func TSFromData(data []byte, copy bool) *Threadsafe
TSFromData creates a new Threadsafe using the provided data. If copy is true the actual slice will be used.
func (*Threadsafe) Data ¶
func (b *Threadsafe) Data(copy bool) []byte
Data returns the data of the bitmap. If copy is false the actual underlying slice will be returned.