bitarray

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: Apache-2.0 Imports: 4 Imported by: 11

Documentation

Overview

Contains efficient array that stores small-range values (up to uint64) in a bit array to optimize storage.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BitSet

type BitSet []Block

BitSet is a set of bits that can be set, cleared and queried.

Example
s := new(BitSet)
s.Set(13)
s.Set(45)
s.Clear(13)
fmt.Printf("s.IsSet(13) = %t; s.IsSet(45) = %t; s.IsSet(30) = %t\n",
	s.IsSet(13), s.IsSet(45), s.IsSet(30))
Output:

s.IsSet(13) = false; s.IsSet(45) = true; s.IsSet(30) = false

func NewBitSet

func NewBitSet(desiredCap uint) *BitSet

Initializes a new BitSet of the specified size.

func (*BitSet) BlockCount

func (s *BitSet) BlockCount() int

Returns the number of blocks of the BitSet.

func (*BitSet) Cap

func (s *BitSet) Cap() uint

Returns the length of the BitSet.

func (*BitSet) Clear

func (s *BitSet) Clear(i uint)

Ensures that the given bit is cleared (unset) in the BitSet.

func (BitSet) DeepCopy

func (s BitSet) DeepCopy() BitSet

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BitSet.

func (BitSet) DeepCopyInto

func (s BitSet) DeepCopyInto(out *BitSet)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (*BitSet) IsSet

func (s *BitSet) IsSet(i uint) bool

Returns true if the given bit is set, false if it is cleared.

func (*BitSet) Set

func (s *BitSet) Set(i uint)

Ensures that the given bit is set in the BitSet.

type Block

type Block uint32

type CompactArray

type CompactArray struct {
	*BitSet    `json:",inline"`
	ItemSize   uint `json:"item,omitempty"`
	ItemsCount uint `json:"count,omitempty"`
}

Provides a wrapper on top of BitSet to store items of arbitrary size (up to 64 bits each) efficiently.

func NewCompactArray

func NewCompactArray(size uint, maxValue Item) (CompactArray, error)

Creates a new CompactArray of specified size.

func (*CompactArray) DeepCopy

func (a *CompactArray) DeepCopy() *CompactArray

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CompactArray.

func (*CompactArray) DeepCopyInto

func (a *CompactArray) DeepCopyInto(out *CompactArray)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (*CompactArray) GetItem

func (a *CompactArray) GetItem(index int) Item

Gets Item at provided index.

func (CompactArray) GetItems

func (a CompactArray) GetItems() []Item

Gets all items stored in the array. The size of the returned array matches the ItemsCount it was initialized with.

func (*CompactArray) SetItem

func (a *CompactArray) SetItem(index int, value Item)

Sets item at index to provided value.

func (CompactArray) String

func (a CompactArray) String() string

Gets a string representation of the array contents. This is a relatively expensive operation.

type Item

type Item = uint64

The biggest Item size that can fit in CompactArray.

Jump to

Keyboard shortcuts

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