bitarray

package module
v0.0.0-...-f792a60 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2014 License: MIT Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

#bitarray

Golang bitarray implementation with variable bit-width. Like java bitset but a bit more powerful.

Introduction

If there are 100,000,000 data. Just a few choice for these data(eg. true or false). Use bitarray to save the state is brilliant. Save your memory.

Usage

Here show a case: Save 1 billion value in bitarray and every value take 2 bits. It will alloced about 238.42mb memory.
Every value will occupy 2-bit.
For 2-bit width value have 4 choices.00 01 10 11

mlen := uint32(1000000000)
bm := NewBitArray(mlen, 2)  
bm.SetB(4, 0x03) // 0000 0011
x := bm.GetB(4) // x will be 0x03

View the test for more.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BitArray

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

func NewBitArray

func NewBitArray(bitmapLen uint32, valueBitWidth byte) *BitArray

bitmapLen: how many bit we should save

func (*BitArray) GetAllocLen

func (s *BitArray) GetAllocLen() int

func (*BitArray) GetB

func (s *BitArray) GetB(pos uint32) byte

func (*BitArray) GetBytes

func (s *BitArray) GetBytes() []byte

func (*BitArray) Init

func (s *BitArray) Init(bitmapLen uint32, valueBitWidth byte) *BitArray

func (*BitArray) SetB

func (s *BitArray) SetB(pos uint32, val byte)

Jump to

Keyboard shortcuts

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