bitarray

package
Version: v0.33.9 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompactBitArray

type CompactBitArray struct {
	ExtraBitsStored byte   `json:"extra_bits"` // The number of extra bits in elems.
	Elems           []byte `json:"bits"`
}

CompactBitArray is an implementation of a space efficient bit array. This is used to ensure that the encoded data takes up a minimal amount of space after amino encoding. This is not thread safe, and is not intended for concurrent usage.

func CompactUnmarshal

func CompactUnmarshal(bz []byte) (*CompactBitArray, error)

CompactUnmarshal is a space efficient decoding for CompactBitArray. It is not amino compatible.

func NewCompactBitArray

func NewCompactBitArray(bits int) *CompactBitArray

NewCompactBitArray returns a new compact bit array. It returns nil if the number of bits is zero.

func (*CompactBitArray) CompactMarshal

func (bA *CompactBitArray) CompactMarshal() []byte

CompactMarshal is a space efficient encoding for CompactBitArray. It is not amino compatible.

func (*CompactBitArray) Copy

func (bA *CompactBitArray) Copy() *CompactBitArray

Copy returns a copy of the provided bit array.

func (*CompactBitArray) GetIndex

func (bA *CompactBitArray) GetIndex(i int) bool

GetIndex returns the bit at index i within the bit array. The behavior is undefined if i >= bA.Size()

func (*CompactBitArray) MarshalJSON

func (bA *CompactBitArray) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface by marshaling bit array using a custom format: a string of '-' or 'x' where 'x' denotes the 1 bit.

func (*CompactBitArray) NumTrueBitsBefore

func (bA *CompactBitArray) NumTrueBitsBefore(index int) int

NumTrueBitsBefore returns the number of bits set to true before the given index. e.g. if bA = _XX__XX, NumOfTrueBitsBefore(4) = 2, since there are two bits set to true before index 4.

func (*CompactBitArray) SetIndex

func (bA *CompactBitArray) SetIndex(i int, v bool) bool

SetIndex sets the bit at index i within the bit array. The behavior is undefined if i >= bA.Size()

func (*CompactBitArray) Size

func (bA *CompactBitArray) Size() int

Size returns the number of bits in the bitarray

func (*CompactBitArray) String

func (bA *CompactBitArray) String() string

String returns a string representation of CompactBitArray: BA{<bit-string>}, where <bit-string> is a sequence of 'x' (1) and '_' (0). The <bit-string> includes spaces and newlines to help people. For a simple sequence of 'x' and '_' characters with no spaces or newlines, see the MarshalJSON() method. Example: "BA{_x_}" or "nil-BitArray" for nil.

func (*CompactBitArray) StringIndented

func (bA *CompactBitArray) StringIndented(indent string) string

StringIndented returns the same thing as String(), but applies the indent at every 10th bit, and twice at every 50th bit.

func (*CompactBitArray) UnmarshalJSON

func (bA *CompactBitArray) UnmarshalJSON(bz []byte) error

UnmarshalJSON implements json.Unmarshaler interface by unmarshaling a custom JSON description.

Jump to

Keyboard shortcuts

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