bitmap

package module
v0.0.0-...-3fa1e4a Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2019 License: BSD-2-Clause Imports: 8 Imported by: 0

README

Package bitmap provides a simple bitmap which allows individual bits to be set and read within a slice of bytes.

The package was inspired by the book "Programming Pearls," by Jon Bentley. The first example in the book is a clever sorting solution which uses a bitmap to sort a file containing up 10 million numeric values in a single pass without loading them all into memory.

http://www.cs.bell-labs.com/cm/cs/pearls/cto.html

func ExampleBitmap () {
    b := bitmap.New(10)
    b.Set(2)
    fmt.Printf("2 in bitmap: %v. 7 in bitmap: %v.\n", b.IsSet(2), b.IsSet(7))
    // Output: 2 in bitmap: true. 7 in bitmap: false.
}

func ExampleValues () {
    b := bitmap.New(10)
    b.Set(2)
    b.Set(7)
    fmt.Println(b.Values())
    // Output: [2 7]
}

Documentation

Overview

Package bitmap provides a simple bitmap which allows individual bits to be set and read within a slice of bytes.

The package was inspired by the book "Programming Pearls," by Jon Bentley. The first example in the book is a clever sorting solution which uses a bitmap to sort a file containing up 10 million numeric values in a single pass without loading them all into memory.

http://www.cs.bell-labs.com/cm/cs/pearls/cto.html

Index

Constants

This section is empty.

Variables

View Source
var ErrOutOfRange = errors.New("Value out of range.")

Functions

This section is empty.

Types

type BitMap

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

BitMap is a struct containing a slice of bytes, being used as a bitmap.

func FromString

func FromString(input string) (BitMap, error)

func New

func New(s uint64) BitMap

New returns a BitMap. It requires a size. A bitmap with a size of eight or less will be one byte in size, and so on.

func (BitMap) IsSet

func (b BitMap) IsSet(i uint64) (bool, error)

IsSet returns a boolean indicating whether the bit is set for the position in question.

func (BitMap) Set

func (b BitMap) Set(i uint64) error

Set sets a position in the bitmap to 1.

func (BitMap) Size

func (b BitMap) Size() uint64

Size returns the size of a bitmap. This is the number of bits.

func (BitMap) ToString

func (b BitMap) ToString() (string, error)

func (BitMap) Unset

func (b BitMap) Unset(i uint64) error

Unset sets a position in the bitmap to 0.

func (BitMap) Values

func (b BitMap) Values() ([]uint64, error)

Values returns a slice of ints represented by the values in the bitmap.

Jump to

Keyboard shortcuts

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