bit

package module
Version: v0.0.0-...-9a4f56f Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2021 License: GPL-3.0 Imports: 2 Imported by: 0

README

bit License GoDoc Pipeline status

Package bit provides a Go implementation of bit arrays.

Install

go get -u gitlab.com/opennota/bit

Similar repositories

Documentation

Overview

Package bit provides a Go implementation of bit arrays.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Array

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

An Array is a variable-sized array of bits. The zero value for Array is an empty Array ready to use.

func NewArray

func NewArray(n int) *Array

NewArray returns a new bit array of n zero bits.

func NewArrayFromSlice

func NewArrayFromSlice(bits []uint64) *Array

NewArrayFromSlice constructs and returns a new bit array from a slice of uint64s.

func (*Array) Add

func (a *Array) Add(v int)

Add adds a bit to the array.

func (*Array) AddBits

func (a *Array) AddBits(v uint64, n int)

AddBits adds the n least significant bits of v to the array.

func (*Array) Bits

func (a *Array) Bits() []uint64

Bits returns raw bits stored in the array as a slice of uint64s.

func (*Array) Clear

func (a *Array) Clear(n int)

Clear sets the nth bit to 0.

func (*Array) Copy

func (a *Array) Copy() *Array

Copy returns a deep copy of the array.

func (*Array) Get

func (a *Array) Get(n int) int

Get returns the value of the nth bit.

func (*Array) GetBool

func (a *Array) GetBool(n int) bool

GetBool returns the value of the nth bit as true (for 1) or false (for 0).

func (*Array) Len

func (a *Array) Len() int

Len returns the number of bits in the array.

func (*Array) Popcnt

func (a *Array) Popcnt() int

Popcnt returns the number of set bits in the array.

func (*Array) Reset

func (a *Array) Reset()

Reset empties the array.

func (*Array) Set

func (a *Array) Set(n int)

Set sets the nth bit to 1.

func (*Array) SetBit

func (a *Array) SetBit(n, v int)

SetBit sets the nth bit to the value of the least significant bit of v, which must be either 0 or 1.

func (*Array) SetBitBool

func (a *Array) SetBitBool(n int, b bool)

SetBitBool sets the nth bit to 0 if b is false and to 1 otherwise.

func (*Array) String

func (a *Array) String() string

String returns the contents of the array as a string of 0s and 1s.

func (*Array) Toggle

func (a *Array) Toggle(n int)

Toggle toggles the nth bit, setting it to 0 if it was 1 and vice versa.

func (*Array) Uint64

func (a *Array) Uint64() uint64

Uint64 returns the bits stored in the array as a uint64. It panics if the array is empty or too big.

func (*Array) WriteTo

func (a *Array) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes the contents of the array to w. It implements the io.WriterTo interface.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL