Documentation ¶
Overview ¶
Package bitseq provides a structure and utilities for representing long bitmask as sequence of run-lenght encoded blocks. It operates direclty on the encoded representation, it does not decode/encode.
Index ¶
- func CheckIfAvailable(head *Sequence, ordinal int) (int, int, error)
- func GetFirstAvailable(head *Sequence) (int, int, error)
- type Handle
- func (h *Handle) Bits() uint32
- func (h *Handle) CheckIfAvailable(ordinal int) (int, int, error)
- func (h *Handle) Destroy()
- func (h *Handle) Exists() bool
- func (h *Handle) FromByteArray(ba []byte) error
- func (h *Handle) GetFirstAvailable() (int, int, error)
- func (h *Handle) Index() uint64
- func (h *Handle) Key() []string
- func (h *Handle) KeyPrefix() []string
- func (h *Handle) PushReservation(bytePos, bitPos int, release bool) error
- func (h *Handle) SetIndex(index uint64)
- func (h *Handle) SetValue(value []byte) error
- func (h *Handle) ToByteArray() ([]byte, error)
- func (h *Handle) Unselected() uint32
- func (h *Handle) Value() []byte
- type Sequence
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckIfAvailable ¶
CheckIfAvailable checks if the bit correspondent to the specified ordinal is unset If the ordinal is beyond the Sequence limits, a negative response is returned
Types ¶
type Handle ¶
Handle contains the sequece representing the bitmask and its identifier
func (*Handle) CheckIfAvailable ¶
CheckIfAvailable checks if the bit correspondent to the specified ordinal is unset If the ordinal is beyond the Sequence limits, a negative response is returned
func (*Handle) Destroy ¶
func (h *Handle) Destroy()
Destroy removes from the datastore the data belonging to this handle
func (*Handle) FromByteArray ¶
FromByteArray reads his handle's data from a byte array
func (*Handle) GetFirstAvailable ¶
GetFirstAvailable returns the byte and bit position of the first unset bit
func (*Handle) KeyPrefix ¶
KeyPrefix returns the immediate parent key that can be used for tree walk
func (*Handle) PushReservation ¶
PushReservation pushes the bit reservation inside the bitmask.
func (*Handle) SetIndex ¶
SetIndex method allows the datastore to store the latest DB Index into this object
func (*Handle) ToByteArray ¶
ToByteArray converts this handle's data into a byte array
func (*Handle) Unselected ¶
Unselected returns the number of bits which are not selected
type Sequence ¶
type Sequence struct { Block uint32 // block representing 4 byte long allocation bitmask Count uint32 // number of consecutive blocks Next *Sequence // next sequence }
Sequence reresents a recurring sequence of 32 bits long bitmasks
func NewSequence ¶
NewSequence returns a sequence initialized to represent a bitmaks of numElements bits
func PushReservation ¶
PushReservation pushes the bit reservation inside the bitmask. Given byte and bit positions, identify the sequence (current) which holds the block containing the affected bit. Create a new block with the modified bit according to the operation (allocate/release). Create a new Sequence containing the new Block and insert it in the proper position. Remove current sequence if empty. Check if new Sequence can be merged with neighbour (previous/Next) sequences.
Identify "current" Sequence containing block:
[prev seq] [current seq] [Next seq]
Based on block position, resulting list of sequences can be any of three forms:
Block position Resulting list of sequences
A) Block is first in current: [prev seq] [new] [modified current seq] [Next seq] B) Block is last in current: [prev seq] [modified current seq] [new] [Next seq] C) Block is in the middle of current: [prev seq] [curr pre] [new] [curr post] [Next seq]
func (*Sequence) FromByteArray ¶
FromByteArray construct the sequence from the byte array TODO (aboch): manage network/host order stuff
func (*Sequence) GetAvailableBit ¶
GetAvailableBit returns the position of the first unset bit in the bitmask represented by this sequence
func (*Sequence) String ¶
String returns a string representation of the block sequence starting from this block
func (*Sequence) ToByteArray ¶
ToByteArray converts the sequence into a byte array TODO (aboch): manage network/host order stuff