bitmap

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2024 License: MIT Imports: 3 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
    })

    // to string, from string
    var b3 bitmap.Bitmap
    b3.Set(1)
    b3.Set(100)
    b3.String() // "2|68719476736"
    b4, err := bitmap.FromString("2|68719476736")

    // Bitmap32 is backed by []uint32 slice
    // Everything else is all the same
    var b32 bitmap.Bitmap32
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bitmap

type Bitmap []uint64

func FromString added in v1.1.0

func FromString(str string) (Bitmap, error)

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) String added in v1.1.0

func (b *Bitmap) String() string

func (*Bitmap) Xor

func (b *Bitmap) Xor(n uint32)

Xor invert n-th bit

type Bitmap32 added in v1.2.0

type Bitmap32 []uint32

func FromString32 added in v1.2.0

func FromString32(str string) (Bitmap32, error)

func (*Bitmap32) Clone added in v1.2.0

func (b *Bitmap32) Clone() Bitmap32

Clone create a copy of the bitmap

func (*Bitmap32) CountDiff added in v1.2.0

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

CountDiff count different bits in two bitmaps

func (*Bitmap32) Has added in v1.2.0

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

Has check if n-th bit is set to 1

func (*Bitmap32) IsEmpty added in v1.2.0

func (b *Bitmap32) IsEmpty() bool

IsEmpty check if the bitmap has any bit set to 1

func (*Bitmap32) Range added in v1.2.0

func (b *Bitmap32) 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 (*Bitmap32) Remove added in v1.2.0

func (b *Bitmap32) Remove(n uint32)

Remove set n-th bit to 0

func (*Bitmap32) Set added in v1.2.0

func (b *Bitmap32) Set(n uint32)

Set set n-th bit to 1

func (*Bitmap32) String added in v1.2.0

func (b *Bitmap32) String() string

func (*Bitmap32) Xor added in v1.2.0

func (b *Bitmap32) 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