bitmap

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Serialize

func Serialize(w io.Writer, bm *Bitmap) (int, error)

Serialize writes this bitmap into a writer, so that it can be deserialised later

Types

type Bitmap

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

Bitmap holds a series of boolean values, efficiently encoded as bits of uint64s

func DeserializeBitmapFromReader

func DeserializeBitmapFromReader(r io.Reader) (*Bitmap, error)

DeserializeBitmapFromReader is the inverse of Serialize

func NewBitmap

func NewBitmap(n int) *Bitmap

NewBitmap allocates a bitmap to hold at least n values

func NewBitmapFromBits

func NewBitmapFromBits(data []uint64, length int) *Bitmap

NewBitmapFromBits leverages a pre-existing bitmap (usually from a file or a reader) and moves it into a new bitmap (does NOT copy)

func NewBitmapFromBools

func NewBitmapFromBools(data []bool) *Bitmap

NewBitmapFromBools initialises a bitmap from a pre-existing bool slice

func Or

func Or(bm1 *Bitmap, bm2 *Bitmap) *Bitmap

Or returns a copy (unlike the method)

func (*Bitmap) AndNot

func (bm *Bitmap) AndNot(obm *Bitmap)

AndNot modified this bitmap in place by executing &^ on each element

func (*Bitmap) Append

func (bm *Bitmap) Append(obm *Bitmap)

Append adds data from an incoming bitmap to this bitmap (in place modification)

func (*Bitmap) Cap

func (bm *Bitmap) Cap() int

Cap returns the length of this bitmap (because the storage uints can have a higher capacity)

func (*Bitmap) Clone

func (bm *Bitmap) Clone() *Bitmap

Clone returns a new bitmap with identical content (but a different backing data structure)

func (*Bitmap) Count

func (bm *Bitmap) Count() int

Count returns the number of true values in a bitmap

func (*Bitmap) Data

func (bm *Bitmap) Data() []uint64

Data returns a slice of the underlying bitmap data

func (*Bitmap) Ensure

func (bm *Bitmap) Ensure(n int)

Ensure makes sure we have at least n capacity in this bitmap (e.g. so that .Get works)

func (*Bitmap) Get

func (bm *Bitmap) Get(n int) bool

Get returns nth bit as a boolean (true for 1, false for 0)

func (*Bitmap) Invert

func (bm *Bitmap) Invert()

Invert flips all the bits in this bitmap

func (*Bitmap) KeepFirstN

func (bm *Bitmap) KeepFirstN(n int)

KeepFirstN leaves only the first n bits set, resets the rest to zeroes does not truncate the underlying storage - the cap is still the same - perhaps we should do this? once we hit the n == count condition, we can discard the rest and lower the cap? will require a fair bit of testing, but should be doable

func (*Bitmap) Or

func (bm *Bitmap) Or(obm *Bitmap)

Or ors this bitmap with another one (a | b)

func (*Bitmap) Set

func (bm *Bitmap) Set(n int, val bool)

Set sets nth bit to `val` - true (1) or false (0)

Jump to

Keyboard shortcuts

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