bitmap

package
v0.0.0-...-a5cfb8a Latest Latest
Warning

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

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

Documentation

Overview

Package bitmap provides utilities for operating on densely-packed arrays of booleans.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesFor

func BytesFor(bits int) int

BytesFor returns the number of bytes necessary to hold the provided number of bits.

func CountOnes

func CountOnes(d Dense) int

CountOnes returns the total number of bits set in d.

func Dot

func Dot(x, y Dense) bool

Dot treats compute the inner product (x^T * y) of x and y, treating them as vectors mod 2.

func Equal

func Equal(a, b Dense) bool

Equal returns true iff a and b contain the same bits.

func Parity

func Parity(d Dense) bool

Parity returns the overall parity of m, with true corresponding to 1 and false to 0.

Types

type Dense

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

A Dense is a bitmap where every bit is explicitly represented.

func And

func And(a, b Dense) Dense

And returns the bitwise AND of two bitmaps.

func DenseFromProto

func DenseFromProto(dba *bb84pb.DenseBitArray) Dense

FromProto converts a DenseBitArray protocol buffer to a dense Map.

func Empty

func Empty() Dense

Empty returns an empty, dense bit array.

func FromString

func FromString(s string) (Dense, error)

FromString converts a string of '1's and '0's to a DenseBitArray.

func NewDense

func NewDense(data []byte, bitLen int) Dense

NewDense returns a new dense bitmap whose contents are a view of data, and whose length is bitLen. If bitLen is longer than data, then trailing zeros are added. If bitLen is negative, then it is inferred from data.

func Not

func Not(d Dense) Dense

Not returns the bitwise negation of a bitmap.

func Or

func Or(a, b Dense) Dense

Or returns the bitwise OR of two bitmaps.

func Select

func Select(data, mask Dense) Dense

Select selects a subset of bits from data, according to which bits are set in mask.

func Slice

func Slice(d Dense, start, end int) (Dense, error)

Slice creates a view into m including bits [start, end).

func XNor

func XNor(a, b Dense) Dense

XNOr returns the bitwise XNOR of two bitmaps.

func XOr

func XOr(a, b Dense) Dense

XOr returns the bitwise XOR of two bitmaps.

func (*Dense) Append

func (d *Dense) Append(d2 Dense)

Append adds the contents of m to the end of d.

func (*Dense) AppendBit

func (d *Dense) AppendBit(bit bool)

AppendBit adds a single bit to the end of d.

func (Dense) Data

func (d Dense) Data() []byte

Data returns a view of the bytes underlying this bitmap. Modifying the returned slice modifies this bitmap.

func (*Dense) Flip

func (d *Dense) Flip(i int)

func (Dense) Get

func (d Dense) Get(i int) bool

Get returns the i-th bit in this bitmap.

func (*Dense) Shuffle

func (d *Dense) Shuffle(r *rand.Rand)

Shuffle randomly permutes the contents of d, using r as a source of randomness.

func (Dense) Size

func (d Dense) Size() int

Size returns the number of bits in this bitmap, excluding implicit trailing zeros.

func (Dense) SizeBytes

func (d Dense) SizeBytes() int

SizeBytes returns the number of bytes in this bitmap, excluding implicit trailing zeros.

func (*Dense) ToProto

func (d *Dense) ToProto() *bb84pb.DenseBitArray

ToProto converts d into an equivalent DenseBitArray proto.

Jump to

Keyboard shortcuts

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