Documentation
¶
Index ¶
- type Bitmap
- func (bm *Bitmap) Equal(other *Bitmap) bool
- func (bm *Bitmap) Get(bit int) (byte, error)
- func (bm *Bitmap) Rank(val, idx int) (int, error)
- func (bm *Bitmap) Select(val, nth int) (int, error)
- func (bm *Bitmap) Set(bit int) error
- func (bitmap Bitmap) String() string
- func (bm *Bitmap) Unset(bit int) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bitmap ¶
type Bitmap struct {
// Capacity is the number of bits the bitmap allows to access
Capacity int
// contains filtered or unexported fields
}
Bitmap provides a size-limited continuous binary structure, allowing access to individiual bits.
It further provides methods to count the number of 0s and 1s up to a given position, respectively find the position of the i-th 0 and 1.
Under the hood it is implemented as a slice of int64 which grows as required.
func New ¶
New initializes a new bitmap.
Capacity specifies the maximum size of the bitmap in bits. Thus the addressable bits will be in the closed interval [0, capacity - 1].
size specifies the size with which the bitmap will be initialized, in bits.
func (*Bitmap) Equal ¶
Equal checks whether the length and content of two bitmaps is equal.
It does not compare their capacities, however.
func (*Bitmap) Get ¶
Get retrieves the value at a given index.
While the returned value is a byte, it will always be either 0 or 1.
An error is returned if the index is invalid.
func (*Bitmap) Rank ¶
Rank returns the number of bits with value val, up to and including position idx.
As an example. Rank(1, 42) would return the number of 1-bits up to and including bit 42.
An error is returned if the index is outside the range of the bitmap, or if val is neither 0 nor 1.
func (*Bitmap) Select ¶
Select returns the index of the nth bit of value val.
As an example, Select(0, 13) would return the index of the 13th 0-bit in the bitmap.
An error is returned if there is no nth bit of value val in the bitmap, or if val is neither 0 nor 1.
func (*Bitmap) Set ¶
Set sets the bit at a given index to 1.
An error is returned if the index is invalid.