Documentation
¶
Index ¶
- type Bitmap
- func (bm *Bitmap) Clear(location int) error
- func (bm *Bitmap) FirstFree(start int) int
- func (bm *Bitmap) FirstSet() int
- func (bm *Bitmap) FreeList() []Contiguous
- func (bm *Bitmap) FromBytes(b []byte)
- func (bm *Bitmap) IsSet(location int) (bool, error)
- func (bm *Bitmap) Set(location int) error
- func (bm *Bitmap) ToBytes() []byte
- type Contiguous
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bitmap ¶
type Bitmap struct {
// contains filtered or unexported fields
}
Bitmap is a structure holding a bitmap
func NewBits ¶
NewBits creates a new bitmap that can address nBits entries. All bits are initially 0 (free).
func NewBytes ¶
NewBytes creates a new bitmap of size bytes; it is not in bits to force the caller to have a complete set
func (*Bitmap) FirstFree ¶
FirstFree returns the first free bit in the bitmap Begins at start, so if you want to find the first free bit, pass start=1. Returns -1 if none found.
func (*Bitmap) FreeList ¶
func (bm *Bitmap) FreeList() []Contiguous
FreeList returns a slicelist of contiguous free locations by location. It is sorted by location. If you want to sort it by size, uses sort.Slice for example, if the bitmap is 10010010 00100000 10000010, it will return
1: 2, // 2 free bits at position 1
4: 2, // 2 free bits at position 4
8: 3, // 3 free bits at position 8
11: 5 // 5 free bits at position 11
17: 5 // 5 free bits at position 17
23: 1, // 1 free bit at position 23
if you want it in reverse order, just reverse the slice.
func (*Bitmap) FromBytes ¶
FromBytes overwrite the existing map with the contents of the bytes. It is the equivalent of BitmapFromBytes, but uses an existing Bitmap.
type Contiguous ¶
Contiguous a position and count of contiguous bits, either free or set