bitmap

package module
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 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.Bitmap64

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

    b.Or(b2) // in-place OR
    b.And(b2) // in-place AND

    // to string, from string
    var b3 bitmap.Bitmap64
    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

    // Bitmap16 is backed by []uint16 slice
    // Everything else is all the same
    var b16 bitmap.Bitmap16

    // Bitmap8 is backed by []uint8 slice
    // Everything else is all the same
    var b8 bitmap.Bitmap8
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bitmap

type Bitmap Bitmap64

type Bitmap16 added in v1.4.0

type Bitmap16 []uint16

func FromString16 added in v1.4.0

func FromString16(str string) (Bitmap16, error)

func (*Bitmap16) And added in v1.4.0

func (b *Bitmap16) And(b2 Bitmap16)

And in-place And operation with another bitmap

func (*Bitmap16) Clone added in v1.4.0

func (b *Bitmap16) Clone() Bitmap16

Clone create a copy of the bitmap

func (*Bitmap16) CountDiff added in v1.4.0

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

CountDiff count different bits in two bitmaps

func (*Bitmap16) Has added in v1.4.0

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

Has check if n-th bit is set to 1

func (*Bitmap16) IsEmpty added in v1.4.0

func (b *Bitmap16) IsEmpty() bool

IsEmpty check if the bitmap has any bit set to 1

func (*Bitmap16) Or added in v1.4.0

func (b *Bitmap16) Or(b2 Bitmap16)

Or in-place OR operation with another bitmap

func (*Bitmap16) Range added in v1.4.0

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

func (b *Bitmap16) Remove(n uint32)

Remove set n-th bit to 0

func (*Bitmap16) Set added in v1.4.0

func (b *Bitmap16) Set(n uint32)

Set set n-th bit to 1

func (*Bitmap16) Shrink added in v1.4.0

func (b *Bitmap16) Shrink()

Shrink remove zero elements at the end of the map

func (*Bitmap16) String added in v1.4.0

func (b *Bitmap16) String() string

func (*Bitmap16) Xor added in v1.4.0

func (b *Bitmap16) 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) And added in v1.3.0

func (b *Bitmap32) And(b2 Bitmap32)

And in-place And operation with another bitmap

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) Or added in v1.3.0

func (b *Bitmap32) Or(b2 Bitmap32)

Or in-place OR operation with another bitmap

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) Shrink added in v1.3.1

func (b *Bitmap32) Shrink()

Shrink remove zero elements at the end of the map

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

type Bitmap64 added in v1.4.0

type Bitmap64 []uint64

func FromString added in v1.1.0

func FromString(str string) (Bitmap64, error)

func (*Bitmap64) And added in v1.4.0

func (b *Bitmap64) And(b2 Bitmap64)

And in-place And operation with another bitmap

func (*Bitmap64) Clone added in v1.4.0

func (b *Bitmap64) Clone() Bitmap64

Clone create a copy of the bitmap

func (*Bitmap64) CountDiff added in v1.4.0

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

CountDiff count different bits in two bitmaps

func (*Bitmap64) Has added in v1.4.0

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

Has check if n-th bit is set to 1

func (*Bitmap64) IsEmpty added in v1.4.0

func (b *Bitmap64) IsEmpty() bool

IsEmpty check if the bitmap has any bit set to 1

func (*Bitmap64) Or added in v1.4.0

func (b *Bitmap64) Or(b2 Bitmap64)

Or in-place OR operation with another bitmap

func (*Bitmap64) Range added in v1.4.0

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

func (b *Bitmap64) Remove(n uint32)

Remove set n-th bit to 0

func (*Bitmap64) Set added in v1.4.0

func (b *Bitmap64) Set(n uint32)

Set set n-th bit to 1

func (*Bitmap64) Shrink added in v1.4.0

func (b *Bitmap64) Shrink()

Shrink remove zero elements at the end of the map

func (*Bitmap64) String added in v1.4.0

func (b *Bitmap64) String() string

func (*Bitmap64) Xor added in v1.4.0

func (b *Bitmap64) Xor(n uint32)

Xor invert n-th bit

type Bitmap8 added in v1.4.0

type Bitmap8 []uint8

func FromString8 added in v1.4.0

func FromString8(str string) (Bitmap8, error)

func (*Bitmap8) And added in v1.4.0

func (b *Bitmap8) And(b2 Bitmap8)

And in-place And operation with another bitmap

func (*Bitmap8) Clone added in v1.4.0

func (b *Bitmap8) Clone() Bitmap8

Clone create a copy of the bitmap

func (*Bitmap8) CountDiff added in v1.4.0

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

CountDiff count different bits in two bitmaps

func (*Bitmap8) Has added in v1.4.0

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

Has check if n-th bit is set to 1

func (*Bitmap8) IsEmpty added in v1.4.0

func (b *Bitmap8) IsEmpty() bool

IsEmpty check if the bitmap has any bit set to 1

func (*Bitmap8) Or added in v1.4.0

func (b *Bitmap8) Or(b2 Bitmap8)

Or in-place OR operation with another bitmap

func (*Bitmap8) Range added in v1.4.0

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

func (b *Bitmap8) Remove(n uint32)

Remove set n-th bit to 0

func (*Bitmap8) Set added in v1.4.0

func (b *Bitmap8) Set(n uint32)

Set set n-th bit to 1

func (*Bitmap8) Shrink added in v1.4.0

func (b *Bitmap8) Shrink()

Shrink remove zero elements at the end of the map

func (*Bitmap8) String added in v1.4.0

func (b *Bitmap8) String() string

func (*Bitmap8) Xor added in v1.4.0

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