bits

package
v0.0.0-...-5b112dc Latest Latest
Warning

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

Go to latest
Published: May 26, 2021 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SZ = 1
View Source
var WS = Arch()

this is the word size of an int(32) in bits. an int(32) requires a min- imum of 4 bytes, each of which are made up of 8 bits, therefore 4x8=32 this same notion applies for int(64) such that 8 bytes * 8 bits/byte = 64

Functions

func Arch

func Arch() int

func Base64StdEncoding

func Base64StdEncoding()

Base64StdEncoding Marshal/Unmarshal BitSet with base64.StdEncoding(Default: base64.URLEncoding)

func Cap

func Cap() uint

Cap returns the total possible capacity, or number of bits

func Get

func Get(m []byte, i int) bool

Get returns the value of bit i from map m. It doesn't check the bounds of the slice.

func GetBit

func GetBit(b byte, i int) bool

GetBit returns the value of bit i of byte b. The bit index must be between 0 and 7.

func Len

func Len(m []byte) int

Len returns the length (in bits) of the provided byteslice. It will always be a multipile of 8 bits.

func LittleEndian

func LittleEndian()

LittleEndian Marshal/Unmarshal Binary as Little Endian(Default: binary.BigEndian)

func NewSlice

func NewSlice(l int) []byte

NewSlice creates a new byteslice with length l (in bits). The actual size in bits might be up to 7 bits larger because they are stored in a byteslice.

func Set

func Set(m []byte, i int, v bool)

Set sets bit i of map m to value v. It doesn't check the bounds of the slice.

func SetBit

func SetBit(b byte, i int, v bool) byte

SetBit sets bit i of byte b to value v. The bit index must be between 0 and 7.

func SetBitRef

func SetBitRef(b *byte, i int, v bool)

SetBitRef sets bit i of byte *b to value v.

Types

type BitSet

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

A BitSet is a set of bits. The zero value of a BitSet is an empty set of length 0.

func From

func From(buf []uint) *BitSet

From is a constructor used to create a BitSet from an array of integers

func NewBitSet

func NewBitSet(length uint) (bset *BitSet)

New creates a new BitSet with a hint that length bits will be required

func (*BitSet) BinaryStorageSize

func (b *BitSet) BinaryStorageSize() int

BinaryStorageSize returns the binary storage requirements

func (*BitSet) Bytes

func (b *BitSet) Bytes() []uint

Bytes returns the bitset as array of integers

func (*BitSet) Cap

func (b *BitSet) Cap() uint

func (*BitSet) Compact

func (b *BitSet) Compact() *BitSet

Compact shrinks BitSet to so that we preserve all set bits, while minimizing memory usage. Compact calls Shrink.

func (*BitSet) Count

func (b *BitSet) Count() uint

Count (number of set bits). Also known as "popcount" or "population count".

func (*BitSet) Equal

func (b *BitSet) Equal(c *BitSet) bool

Equal tests the equivalence of two BitSets. False if they are of different sizes, otherwise true only if all the same bits are set

func (*BitSet) Flip

func (b *BitSet) Flip(i uint) *BitSet

Flip bit at i. If i>= Cap(), this function will panic. Warning: using a very large value for 'i' may lead to a memory shortage and a panic: the caller is responsible for providing sensible parameters in line with their memory capacity.

func (*BitSet) Has

func (b *BitSet) Has(i uint) bool

Has whether bit i is set.

func (*BitSet) InPlaceUnion

func (b *BitSet) InPlaceUnion(compare *BitSet)

InPlaceUnion creates the destructive union of base set and compare set. This is the BitSet equivalent of | (or).

func (*BitSet) Len

func (b *BitSet) Len() uint

Len returns the number of bits in the BitSet. Note the difference to method Count, see example.

func (*BitSet) MarshalBinary

func (b *BitSet) MarshalBinary() ([]byte, error)

MarshalBinary encodes a BitSet into a binary form and returns the result.

func (*BitSet) MarshalJSON

func (b *BitSet) MarshalJSON() ([]byte, error)

MarshalJSON marshals a BitSet as a JSON structure

func (*BitSet) ReadFrom

func (b *BitSet) ReadFrom(stream io.Reader) (int64, error)

ReadFrom reads a BitSet from a stream written using WriteTo

func (*BitSet) Set

func (b *BitSet) Set(i uint) *BitSet

Set bit i to 1, the capacity of the bitset is automatically increased accordingly. If i>= Cap(), this function will panic. Warning: using a very large value for 'i' may lead to a memory shortage and a panic: the caller is responsible for providing sensible parameters in line with their memory capacity.

func (*BitSet) SetAll

func (b *BitSet) SetAll() *BitSet

SetAll sets the entire BitSet

func (*BitSet) SetTo

func (b *BitSet) SetTo(i uint, value bool) *BitSet

SetTo sets bit i to value. If i>= Cap(), this function will panic. Warning: using a very large value for 'i' may lead to a memory shortage and a panic: the caller is responsible for providing sensible parameters in line with their memory capacity.

func (*BitSet) Shrink

func (b *BitSet) Shrink(lastbitindex uint) *BitSet

Shrink shrinks BitSet so that the provided value is the last possible set value. It clears all bits > the provided index and reduces the size and length of the set.

Note that the parameter value is not the new length in bits: it is the maximal value that can be stored in the bitset after the function call. The new length in bits is the parameter value + 1. Thus it is not possible to use this function to set the length to 0, the minimal value of the length after this function call is 1.

A new slice is allocated to store the new bits, so you may see an increase in memory usage until the GC runs. Normally this should not be a problem, but if you have an extremely large BitSet its important to understand that the old BitSet will remain in memory until the GC frees it.

func (*BitSet) String

func (b *BitSet) String() string

print binary value of bitset

func (*BitSet) UnmarshalBinary

func (b *BitSet) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes the binary form generated by MarshalBinary.

func (*BitSet) UnmarshalJSON

func (b *BitSet) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals a BitSet from JSON created using MarshalJSON

func (*BitSet) Unset

func (b *BitSet) Unset(i uint) *BitSet

Unset bit i to 0

func (*BitSet) UnsetAll

func (b *BitSet) UnsetAll() *BitSet

UnsetAll clears the entire BitSet

func (*BitSet) WriteTo

func (b *BitSet) WriteTo(stream io.Writer) (int64, error)

WriteTo writes a BitSet to a stream

type BitVec

type BitVec []int

func NewBitVec

func NewBitVec(n int) BitVec

func (BitVec) Del

func (bv BitVec) Del(k int)

func (BitVec) Get

func (bv BitVec) Get(k int) int

func (BitVec) Has

func (bv BitVec) Has(k int) bool

func (BitVec) Set

func (bv BitVec) Set(k int, v bool)

type Bitmap

type Bitmap []byte

Bitmap is a byteslice with bitmap functions. Creating one form existing data is as simple as bitmap := Bitmap(data).

func NewBitmap

func NewBitmap(l int) Bitmap

NewBitmap creates a new Bitmap instance with length l (in bits)

func (Bitmap) Data

func (b Bitmap) Data(copy bool) []byte

Data returns the data of the bitmap. If copy is false the actual underlying slice will be returned.

func (Bitmap) Get

func (b Bitmap) Get(i int) bool

Get wraps around the Get function.

func (Bitmap) Len

func (b Bitmap) Len() int

Len wraps around the Len function.

func (Bitmap) Set

func (b Bitmap) Set(i int, v bool)

Set wraps around the Set function.

Jump to

Keyboard shortcuts

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