tendermint: github.com/tendermint/tendermint/libs/bits Index | Files

package bits

import "github.com/tendermint/tendermint/libs/bits"

Index

Package Files

bit_array.go

type BitArray Uses

type BitArray struct {
    Bits  int      `json:"bits"`  // NOTE: persisted via reflect, must be exported
    Elems []uint64 `json:"elems"` // NOTE: persisted via reflect, must be exported
    // contains filtered or unexported fields
}

BitArray is a thread-safe implementation of a bit array.

func NewBitArray Uses

func NewBitArray(bits int) *BitArray

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

func (*BitArray) And Uses

func (bA *BitArray) And(o *BitArray) *BitArray

And returns a bit array resulting from a bitwise AND of the two bit arrays. If the two bit-arrys have different lengths, this truncates the larger of the two bit-arrays from the right. Thus the size of the return value is the minimum of the two provided bit arrays.

func (*BitArray) Bytes Uses

func (bA *BitArray) Bytes() []byte

Bytes returns the byte representation of the bits within the bitarray.

func (*BitArray) Copy Uses

func (bA *BitArray) Copy() *BitArray

Copy returns a copy of the provided bit array.

func (*BitArray) FromProto Uses

func (bA *BitArray) FromProto(protoBitArray *tmprotobits.BitArray) error

FromProto sets BitArray to the given protoBitArray. It returns an error if protoBitArray is invalid.

XXX: It does not copy the array.

func (*BitArray) GetIndex Uses

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

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

func (*BitArray) IsEmpty Uses

func (bA *BitArray) IsEmpty() bool

IsEmpty returns true iff all bits in the bit array are 0

func (*BitArray) IsFull Uses

func (bA *BitArray) IsFull() bool

IsFull returns true iff all bits in the bit array are 1.

func (*BitArray) MarshalJSON Uses

func (bA *BitArray) 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 (*BitArray) Not Uses

func (bA *BitArray) Not() *BitArray

Not returns a bit array resulting from a bitwise Not of the provided bit array.

func (*BitArray) Or Uses

func (bA *BitArray) Or(o *BitArray) *BitArray

Or returns a bit array resulting from a bitwise OR of the two bit arrays. If the two bit-arrys have different lengths, Or right-pads the smaller of the two bit-arrays with zeroes. Thus the size of the return value is the maximum of the two provided bit arrays.

func (*BitArray) PickRandom Uses

func (bA *BitArray) PickRandom() (int, bool)

PickRandom returns a random index for a set bit in the bit array. If there is no such value, it returns 0, false. It uses the global randomness in `random.go` to get this index.

func (*BitArray) SetIndex Uses

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

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

func (*BitArray) Size Uses

func (bA *BitArray) Size() int

Size returns the number of bits in the bitarray

func (*BitArray) String Uses

func (bA *BitArray) String() string

String returns a string representation of BitArray: 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 (*BitArray) StringIndented Uses

func (bA *BitArray) 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 (*BitArray) Sub Uses

func (bA *BitArray) Sub(o *BitArray) *BitArray

Sub subtracts the two bit-arrays bitwise, without carrying the bits. Note that carryless subtraction of a - b is (a and not b). The output is the same as bA, regardless of o's size. If bA is longer than o, o is right padded with zeroes

func (*BitArray) ToProto Uses

func (bA *BitArray) ToProto() *tmprotobits.BitArray

ToProto converts BitArray to protobuf. It returns nil if BitArray is nil/empty.

XXX: It does not copy the array.

func (*BitArray) UnmarshalJSON Uses

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

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

func (*BitArray) Update Uses

func (bA *BitArray) Update(o *BitArray)

Update sets the bA's bits to be that of the other bit array. The copying begins from the begin of both bit arrays.

Package bits imports 10 packages (graph) and is imported by 6 packages. Updated 2021-01-05. Refresh now. Tools for package owners.