bitmap

package module
v0.0.0-...-23cd2fb Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2015 License: MIT Imports: 3 Imported by: 31

README

Bitmap (Go)

Package bitmap implements (thread-safe) bitmap functions and abstractions

Install

go get github.com/boljen/go-bitmap

Documentation

See godoc

Example

package main

import (
    "fmt"
    "github.com/boljen/go-bitmap"
)

func main() {
    bm := bitmap.New(100)
    bm.Set(0, true)
    fmt.Println(bm.Get(0))
}

License

MIT

Documentation

Overview

Package bitmap implements (thread-safe) bitmap functions and abstractions.

Installation

go get github.com/boljen/go-bitmap

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(m []byte, i int) bool

Get returns the value of bit i from map m. It doesn't check the bounds of the slice.

func GetAtomicUint32

func GetAtomicUint32(bitmap []uint32, targetBit int) bool

GetAtomicUint32 gets the target bit from an uint32 encoded bitmap.

func GetBit

func GetBit(b byte, i int) bool

GetBit returns the value of bit i of byte b. The bit index must be between 0 and 7.

func Len

func Len(m []byte) int

Len returns the length (in bits) of the provided byteslice. It will always be a multipile of 8 bits.

func NewSlice

func NewSlice(l int) []byte

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 Set

func Set(m []byte, i int, v bool)

Set sets bit i of map m to value v. It doesn't check the bounds of the slice.

func SetAtomic

func SetAtomic(bitmap []byte, targetBit int, targetValue bool)

SetAtomic is similar to Set except that it performs the operation atomically.

func SetAtomicUint32

func SetAtomicUint32(bitmap []uint32, targetBit int, targetValue bool)

SetAtomicUint32 sets the target bit to the target value inside the uint32 encded bitmap.

func SetBit

func SetBit(b byte, i int, v bool) byte

SetBit sets bit i of byte b to value v. The bit index must be between 0 and 7.

func SetBitRef

func SetBitRef(b *byte, i int, v bool)

SetBitRef sets bit i of byte *b to value v.

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).

func New

func New(l int) Bitmap

New creates a new Bitmap instance with length l (in bits).

func (Bitmap) Data

func (b Bitmap) Data(copy bool) []byte

Data returns the data of the bitmap. If copy is false the actual underlying slice will be returned.

func (Bitmap) Get

func (b Bitmap) Get(i int) bool

Get wraps around the Get function.

func (Bitmap) Len

func (b Bitmap) Len() int

Len wraps around the Len function.

func (Bitmap) Set

func (b Bitmap) Set(i int, v bool)

Set wraps around the Set function.

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) Get

func (c Concurrent) Get(b int) bool

Get wraps around the Get function.

func (Concurrent) Len

func (c Concurrent) Len() int

Len wraps around the Len function.

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 NewTS

func NewTS(length int) *Threadsafe

NewTS creates a new Threadsafe instance.

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.

func (Threadsafe) Get

func (b Threadsafe) Get(i int) bool

Get wraps around the Get function.

func (Threadsafe) Len

func (b Threadsafe) Len() int

Len wraps around the Len function.

func (Threadsafe) Set

func (b Threadsafe) Set(i int, v bool)

Set wraps around the Set function.

Jump to

Keyboard shortcuts

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