bitfield

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2023 License: Apache-2.0, MIT Imports: 2 Imported by: 14

README

go-bitfield

This is a simple bitfield package that's about 2-3x faster than using big.Ints from the standard library. It also has a better interface (and, e.g., supports counting ones).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bitfield

type Bitfield []byte

Bitfield is, well, a bitfield.

func FromBytes

func FromBytes(size int, bits []byte) (Bitfield, error)

FromBytes constructs a new bitfield from a serialized bitfield.

func NewBitfield

func NewBitfield(size int) (Bitfield, error)

NewBitfield creates a new fixed-sized Bitfield (allocated up-front).

func (Bitfield) Bit

func (bf Bitfield) Bit(i int) bool

Bit returns the ith bit.

Panics if the bit is out of bounds.

func (Bitfield) Bytes

func (bf Bitfield) Bytes() []byte

Bytes returns the Bitfield as a byte string.

This function *does not* copy.

func (Bitfield) Ones

func (bf Bitfield) Ones() int

Ones returns the number of bits set.

func (Bitfield) OnesAfter

func (bf Bitfield) OnesAfter(i int) int

OnesAfter returns the number of bits set *after* this bit.

func (Bitfield) OnesBefore

func (bf Bitfield) OnesBefore(i int) int

OnesBefore returns the number of bits set *before* this bit.

func (Bitfield) SetBit

func (bf Bitfield) SetBit(i int)

SetBit sets the ith bit.

Panics if the bit is out of bounds.

func (Bitfield) SetBytes

func (bf Bitfield) SetBytes(b []byte)

SetBytes sets the bits to the given byte array.

Panics if 'b' is larger than the bitfield.

func (Bitfield) UnsetBit

func (bf Bitfield) UnsetBit(i int)

UnsetBit unsets the ith bit.

Panics if the bit is out of bounds.

Jump to

Keyboard shortcuts

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