Documentation ¶
Overview ¶
Package bitseq efficiently implements a general-purpose infinite sequence of bits.
Index ¶
- Variables
- func Read(dest *Store, r io.Reader) error
- type Store
- func (s *Store) Clear()
- func (s Store) CountTrue() int
- func (s *Store) Crop()
- func (s Store) Get(index int) bool
- func (s Store) NextFalse(after int) int
- func (s Store) NextTrue(after int) (int, bool)
- func (s Store) PrevTrue(before int) (int, bool)
- func (s *Store) Set(index int, bit bool)
- func (s Store) String() string
- func (s Store) Write(w io.Writer) error
Constants ¶
This section is empty.
Variables ¶
var ErrRange = errors.New("value out of range")
Functions ¶
func Read ¶
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 ¶
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 ¶
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 ¶
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) PrevTrue ¶ added in v2.13.0
PrevTrue returns the index of the previous true bit found before the given index. To start at the end, start with PrevTrue(-1). If the second return value is false, then the search has finished, and the remaining sequence prefix is either empty or all false bits.