bits

package
v0.0.0-...-6a307ac Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2022 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NewUint   = New[uint, uint]
	NewUint8  = New[uint8, uint]
	NewUint16 = New[uint16, uint]
	NewUint32 = New[uint32, uint]
	NewUint64 = New[uint64, uint]
)

handy aliases for instantiation

Functions

This section is empty.

Types

type Bitset

type Bitset[W Width, V bitset.Value] struct {
	logical.IterableMixin[V]
	// contains filtered or unexported fields
}

Bitset is a threadsafe container for storing a set of bits.

func New

func New[W Width, V bitset.Value](size uint) *Bitset[W, V]

New instantiates a new bitset with an initial size of size. This size parameter refers to the number of bitset elements, not the underlying storage.

func (*Bitset[W, V]) And

func (a *Bitset[W, V]) And(b *Bitset[W, V]) (aAndB *Bitset[W, V])

And computes and returns the intersection of two bitsets. It does not modify either bitset.

func (*Bitset[V, W]) Cap

func (s *Bitset[V, W]) Cap() int

Cap is the available number of bits in the underlying data store (rounded up to word size).

func (*Bitset[W, V]) Clear

func (s *Bitset[W, V]) Clear()

Clear unsets all elements in the bitset, and sets the internal size to zero.

func (*Bitset[W, V]) Copy

func (s *Bitset[W, V]) Copy() *Bitset[W, V]

Copy returns a deep copy of the bitset.

func (*Bitset[W, V]) Get

func (s *Bitset[W, V]) Get(index V) bool

Get returns whether or not a value is set in the underlying bitset. Getting a value outside of what's stored automatically returns false.

func (*Bitset[W, V]) Iterate

func (s *Bitset[W, V]) Iterate() (iterable.Iter[V], uint)

func (*Bitset[V, W]) Len

func (s *Bitset[V, W]) Len() int

Len is the used number of bits in the underlying data store (rounded up to word size).

func (*Bitset[W, V]) Or

func (a *Bitset[W, V]) Or(b *Bitset[W, V]) (aOrB *Bitset[W, V])

Or computes and returns the union of two bitsets. It does not modify either bitset.

func (*Bitset[V, W]) Pop

func (s *Bitset[V, W]) Pop() uint

Pop is the number of bits set in the underlying data store.

func (*Bitset[W, V]) Set

func (s *Bitset[W, V]) Set(indices ...V)

Set one or more values in the bitset. The bitset will be expanded if necessary.

func (*Bitset[W, V]) Unset

func (s *Bitset[W, V]) Unset(indices ...V)

Unset one or more values in the bitset. Indices outside of range are ignored.

type Iterator

type Iterator[W Width, V bitset.Value] struct {
	Bitset[W, V]
	// contains filtered or unexported fields
}

func (*Iterator[W, V]) Next

func (it *Iterator[W, V]) Next() (V, bool)

type Uint

type Uint = Bitset[uint, uint]

Basic internal type aliases.

type Uint16

type Uint16 = Bitset[uint16, uint]

Basic internal type aliases.

type Uint32

type Uint32 = Bitset[uint32, uint]

Basic internal type aliases.

type Uint64

type Uint64 = Bitset[uint64, uint]

Basic internal type aliases.

type Uint8

type Uint8 = Bitset[uint8, uint]

Basic internal type aliases.

type Width

type Width interface {
	uint8 | uint16 | uint32 | uint64 |
		uintptr | ~uint // machine-optimized sizes
}

Width is the underlying word-size for storing bit fields. It mostly matters for allocation and indexing

Jump to

Keyboard shortcuts

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