bitmap

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2024 License: MIT Imports: 1 Imported by: 1

README

Bitmap

Yet another bitmap implementation written in go.

Installation

$ go get -v github.com/f1monkey/bitmap

Usage

func main() {
    var b bitmap.Bitmap

    b.IsEmpty() // true

    b.Set(0)
    b.Has(0) // true
    b.Remove(0)
    b.Has(0) // false

    b.Xor(1000)
    b.Has(1000) // true
    b.Xor(1000)
    b.Has(1000) // false

    b2 := b.Clone() // copy of "b"

    b2.Range(func(n uint32) bool {
        fmt.PrintLn(n)
        return true
    })
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bitmap

type Bitmap []uint64

func (*Bitmap) Clone

func (b *Bitmap) Clone() Bitmap

Clone create a copy of the bitmap

func (*Bitmap) CountDiff

func (b *Bitmap) CountDiff(b2 Bitmap) int

CountDiff count different bits in two bitmaps

func (*Bitmap) Has

func (b *Bitmap) Has(n uint32) bool

Has check if n-th bit is set to 1

func (*Bitmap) IsEmpty

func (b *Bitmap) IsEmpty() bool

IsEmpty check if the bitmap has any bit set to 1

func (*Bitmap) Range

func (b *Bitmap) Range(f func(n uint32) bool)

Range call the passed callback with all bits set to 1. If the callback returns false, the method exits

func (*Bitmap) Remove

func (b *Bitmap) Remove(n uint32)

Remove set n-th bit to 0

func (*Bitmap) Set

func (b *Bitmap) Set(n uint32)

Set set n-th bit to 1

func (*Bitmap) Xor

func (b *Bitmap) Xor(n uint32)

Xor invert n-th bit

Jump to

Keyboard shortcuts

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