bitset256

package
v1.3.9 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2021 License: Apache-2.0 Imports: 3 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bitset256

type Bitset256 [4]uint64

Bitset256 is an efficient way to store individual bits corresponding to 256 values (i.e., using a byte as an index).

func FromBytes

func FromBytes(ba []byte) (*Bitset256, error)

FromBytes takes a slice of 32 bytes and builds a Bitset256 from it, following the same rules as AsBytes (the last byte in the slice corresponds to the zeroth bits).

func FromHex

func FromHex(s string) (*Bitset256, error)

FromHex builds a Bitset256 from a hex string like the one AsHex generates.

func New

func New(ixs ...byte) *Bitset256

New creates a new bitset and allows setting some of its bits at the same time.

func (*Bitset256) AsBytes

func (b *Bitset256) AsBytes() []byte

AsBytes returns the bitset as a slice of 32 bytes, where the 0 bits in the bitset are in the last element of the slice (basically, big-endian format). This is so that rendering the slice to a visual format will show the bits in an expected order.

func (*Bitset256) AsHex

func (b *Bitset256) AsHex() string

AsHex returns a string representation of the bitset as a 256-bit number in hex (64 characters). It follows the same rules as AsBytes.

func (*Bitset256) Clear

func (b *Bitset256) Clear(ix byte) *Bitset256

Clear unconditionally forces a single bit to 0 and returns the pointer to the bitset.

func (*Bitset256) Clone

func (b *Bitset256) Clone() *Bitset256

Clone creates a copy of a bitset.

func (*Bitset256) Count

func (b *Bitset256) Count() int

Count returns the number of 1 bits that are set.

func (*Bitset256) Equals

func (b *Bitset256) Equals(other *Bitset256) bool

Equals returns true if the two bitsets have identical contents.

func (*Bitset256) Get

func (b *Bitset256) Get(ix byte) bool

Get retrieves the value of a single bit at the given index.

func (*Bitset256) Indices

func (b *Bitset256) Indices() []byte

Indices returns an []byte where the values are the indices of all the 1 bits that are set, in sorted order from 0. The length of the slice is equal to b.Count(). This is fairly heavily optimized.

func (*Bitset256) Intersect

func (b *Bitset256) Intersect(other *Bitset256) *Bitset256

Intersect returns a pointer to a new Bitset256 that is the intersection of its two source bitsets (the only bits that are set are the ones where both source sets had a 1 bit).

func (*Bitset256) IsSubsetOf

func (b *Bitset256) IsSubsetOf(other *Bitset256) bool

IsSubsetOf returns true if all of the bits in a bitset are also in the other bitset.

func (*Bitset256) Less

func (b *Bitset256) Less(other *Bitset256) bool

Less returns true if, when expressed as a number, b would be strictly less than other.

func (*Bitset256) Set

func (b *Bitset256) Set(ix byte) *Bitset256

Set unconditionally forces a single bit at the index to 1 and returns the pointer to the bitset.

func (*Bitset256) String

func (b *Bitset256) String() string

String implements Stringer for Bitset256.

func (*Bitset256) Toggle

func (b *Bitset256) Toggle(ix byte) *Bitset256

Toggle reverses the state of a single bit at the index and returns the pointer to the bitset.

func (*Bitset256) Union

func (b *Bitset256) Union(other *Bitset256) *Bitset256

Union returns a pointer to a new Bitset256 that is the union of its two source bitsets (the only bits that are set are the ones where either source set had a 1 bit).

Jump to

Keyboard shortcuts

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