bitfield

package
v0.4.11 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2019 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package bitfield provides support for manipulating bits in a []byte.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NumBytes

func NumBytes(length uint32) int

Types

type Bitfield

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

Bitfield is described in BEP 3.

func New

func New(length uint32) *Bitfield

New creates a new Bitfield of length bits.

func NewBytes

func NewBytes(b []byte, length uint32) (*Bitfield, error)

NewBytes returns a new Bitfield from bytes. Bytes in b are not copied. Unused bits in last byte are cleared. Panics if b is not big enough to hold "length" bits.

func (*Bitfield) All

func (b *Bitfield) All() bool

All returns true if all bits are set, false otherwise.

func (*Bitfield) And

func (b *Bitfield) And(b2 *Bitfield)

func (*Bitfield) Bytes

func (b *Bitfield) Bytes() []byte

Bytes returns bytes in b. If you modify the returned slice the bits in b are modified too.

func (*Bitfield) Clear

func (b *Bitfield) Clear(i uint32)

Clear bit i. 0 is the most significant bit. Panics if i >= b.Len().

func (*Bitfield) ClearAll

func (b *Bitfield) ClearAll()

ClearAll clears all bits.

func (*Bitfield) Copy

func (b *Bitfield) Copy() *Bitfield

func (*Bitfield) Count

func (b *Bitfield) Count() uint32

Count returns the count of set bits.

func (*Bitfield) FirstClear

func (b *Bitfield) FirstClear(start uint32) (uint32, bool)

FirstClear returns the index of the first bit that is not set starting from start.

func (*Bitfield) FirstSet

func (b *Bitfield) FirstSet(start uint32) (uint32, bool)

FirstSet returns the index of the first bit that is set starting from start.

func (*Bitfield) Hex

func (b *Bitfield) Hex() string

Hex returns bytes as string. If not all the bits in last byte are used, they encode as not set.

func (*Bitfield) Len

func (b *Bitfield) Len() uint32

Len returns the number of bits as given to New.

func (*Bitfield) Or

func (b *Bitfield) Or(b2 *Bitfield)

func (*Bitfield) Set

func (b *Bitfield) Set(i uint32)

Set bit i. 0 is the most significant bit. Panics if i >= b.Len().

func (*Bitfield) SetTo

func (b *Bitfield) SetTo(i uint32, value bool)

SetTo sets bit i to value. Panics if i >= b.Len().

func (*Bitfield) Test

func (b *Bitfield) Test(i uint32) bool

Test bit i. 0 is the most significant bit. Panics if i >= b.Len().

Jump to

Keyboard shortcuts

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