bitseq

package
v2.12.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package bitseq efficiently implements a general-purpose infinite sequence of bits.

Index

Constants

This section is empty.

Variables

View Source
var ErrRange = errors.New("value out of range")

Functions

func Read

func Read(dest *Store, r io.Reader) error

Read reads an opaque binary representation from r into the provided Store, replacing its existing contents iff successful.

Important: While relatively robust against corrupt data, care should be taken when parsing arbitrary input. A malicious actor could craft an input that would allocate a large amount of memory, or attempt to extract information by continuing to consume from the reader. io.LimitReader may be helpful here.

Types

type Store

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

Store is an "infinite" sequence of bits. Trailing zero bits do not necessarily consume any memory.

The zero-value Store is a useful value. The store is not suitable for concurrent use without additional synchronization.

func (*Store) Crop added in v2.12.0

func (s *Store) Crop()

Crop attempts to reclaim any surplus backing memory consumed by trailing zero bits.

func (*Store) Get

func (s *Store) Get(index int) bool

Get looks up a bit at a given index, returning true iff it has been set. Panics if index is less than zero.

func (*Store) NextFalse

func (s *Store) NextFalse(after int) int

NextFalse returns the index of the next false bit found after the given index. To start at the beginning, start with NextFalse(-1).

func (*Store) NextTrue

func (s *Store) NextTrue(after int) (int, bool)

NextTrue returns the index of the next true bit found after the given index. To start at the beginning, start with NextTrue(-1). If the second return value is false, then the search has finished, and the remaining sequence is an infinite sequence of false bits.

func (*Store) Set

func (s *Store) Set(index int, bit bool)

Set sets a bit to true or false at given index.

func (*Store) String

func (s *Store) String() string

String implements the stringer interface, and prints a bit sequence as '1' and '0' characters from left-to-right. Trailing zeroes are omitted.

func (*Store) Write

func (s *Store) Write(w io.Writer) error

Write writes an opaque binary representation of the Store into w.

Jump to

Keyboard shortcuts

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