bitslice

package
v2.0.0-dev0.0.19 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: BSD-3-Clause Imports: 1 Imported by: 0

README

bitslice

Docs: GoDoc

bitslice implements a simple slice-of-bits using a []byte slice for storage, used for efficient storage of boolean data, such as projection connectivity patterns.

Documentation

Overview

Package bitslice implements a simple slice-of-bits using a []byte slice for storage. used for efficient storage of boolean data, such as projection connectivity patterns.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BitIndex

func BitIndex(idx int) (byte int, bit uint32)

BitIndex returns the byte, bit index of given bit index

Types

type Slice

type Slice []byte

bitslice.Slice is the slice of []byte that holds the bits. first byte maintains the number of bits used in the last byte (0-7). when 0 then prior byte is all full and a new one must be added for append.

func Make

func Make(ln, cp int) Slice

Make makes a new bitslice of given length and capacity (optional, pass 0 for default) *bits* (rounds up 1 for both). also reserves first byte for extra bits value

func (*Slice) Append

func (bs *Slice) Append(val bool) Slice

Append adds a bit to the slice and returns possibly new slice, possibly old slice..

func (*Slice) Cap

func (bs *Slice) Cap() int

Cap returns the capacity of the slice in bits -- always modulo 8

func (*Slice) Clone

func (bs *Slice) Clone() Slice

Clone creates a new copy of this bitslice with separate memory

func (*Slice) Delete

func (bs *Slice) Delete(start, n int) Slice

Delete returns a new bit slice with N elements removed starting at given index. This must be a copy given the nature of the 8-bit aliasing.

func (*Slice) Index

func (bs *Slice) Index(idx int) bool

Index returns bit value at given bit index

func (*Slice) Insert

func (bs *Slice) Insert(start, n int) Slice

Insert returns a new bit slice with N false elements inserted starting at given index. This must be a copy given the nature of the 8-bit aliasing.

func (*Slice) Len

func (bs *Slice) Len() int

Len returns the length of the slice in bits

func (*Slice) Set

func (bs *Slice) Set(idx int, val bool)

Set sets value of given bit index -- no extra range checking is performed -- will panic if out of range

func (*Slice) SetAll

func (bs *Slice) SetAll(val bool)

SetAll sets all values to either on or off -- much faster than setting individual bits

func (*Slice) SetLen

func (bs *Slice) SetLen(ln int)

SetLen sets the length of the slice, copying values if a new allocation is required

func (*Slice) String

func (bs *Slice) String() string

String satisfies the fmt.Stringer interface

func (*Slice) SubSlice

func (bs *Slice) SubSlice(start, end int) Slice

SubSlice returns a new Slice from given start, end range indexes of this slice if end is <= 0 then the length of the source slice is used (equivalent to omitting the number after the : in a Go subslice expression)

func (*Slice) ToBools

func (bs *Slice) ToBools() []bool

ToBools converts to a []bool slice

Jump to

Keyboard shortcuts

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