Documentation ¶
Overview ¶
Package bitdata contains types and methods in order to deal with array of bits
Index ¶
- Variables
- func GetLengthInBit(s string) uint64
- func GetTotalBitCount(strings []string) uint64
- type BitData
- func (s1 *BitData) AppendBit(bit bool) error
- func (s1 *BitData) AppendBits(s2 *BitData) error
- func (s1 *BitData) BitToByte() ([]byte, error)
- func (s1 *BitData) BitToString() (string, error)
- func (s1 *BitData) BitToStringOfLengthL(l uint64) (string, error)
- func (s1 *BitData) BitToTrimmedString() (string, error)
- func (s1 *BitData) ClearBit(index uint64) error
- func (s1 *BitData) GetBit(index uint64) (bool, error)
- func (s1 *BitData) GetDifferentPrefix(s2 *BitData) (*BitData, error)
- func (s1 *BitData) GetDifferentSuffix(s2 *BitData) (*BitData, error)
- func (s1 *BitData) GetFirstLBits(l uint64) (*BitData, error)
- func (s1 *BitData) Rank1(i uint64) (uint64, error)
- func (s1 *BitData) Select1(i uint64) (uint64, error)
- func (s1 *BitData) SetBit(index uint64) error
- func (s1 *BitData) String() string
- type ErrInvalidPosition
Constants ¶
This section is empty.
Variables ¶
var ( // ErrIndexOutOfBound represents an index out of bound error ErrIndexOutOfBound = errors.New("index out of bound") // ErrNotInitBitData tells that the BitData on which you are operating is not initialized ErrNotInitBitData = errors.New("cannot append to a non initialized BitData") // ErrInvalidString indicates that the string on which you are working is not valid ErrInvalidString = errors.New("bitdata should be a valid string") // ErrLessThanIOnes is returned by Select1 or Rank1 when you are trying to access to a "1" that does not exist ErrLessThanIOnes = errors.New("there are less than i 1s in the array") // ErrInvalidI is returned when i is greater than the length of the array ErrInvalidI = errors.New("i should not be greater than the length of the array") // ErrZeroI is returned when you are passing a value of i equal to 0 ErrZeroI = errors.New("i should be greater than 0") )
Functions ¶
func GetLengthInBit ¶
GetLengthInBit returns the length in bit of the string s.
func GetTotalBitCount ¶
GetTotalBitCount , given a slice of string, returns the total count of bits for each string in the slice.
Types ¶
type BitData ¶
type BitData struct { // Number of significant bits in the BitArray. Len uint64 // contains filtered or unexported fields }
BitData type abstracts a string accessible as a sequence of bits; it also contains information about the number of bits.
func GetBitData ¶
GetBitData , given a string 's', returns a pointer to a BitData encoding the string s. If something has gone wrong, returns a nil pointer and and error.
func (*BitData) AppendBits ¶
AppendBits appends the bits of a BitData (s2) onto the s1 BitData.
func (*BitData) BitToByte ¶
BitToByte returns a byte array in which each byte represents a character of the string at first stored as BitData. If something has gone wrong it returns a nil array an an error.
func (*BitData) BitToString ¶
BitToString returns a decoded string given a BitData. If something has gone wrong it returns a nil string and an error.
func (*BitData) BitToStringOfLengthL ¶
BitToStringOfLengthL returns a decoded string of length l bits given a BitData. If something has gone wrong it returns a nil string and an error.
func (*BitData) BitToTrimmedString ¶
BitToTrimmedString returns a decoded and trimmed string given a BitData. If something has gone wrong it returns a nil string and an error.
func (*BitData) ClearBit ¶
ClearBit reset a bit in the BitData if the index is not out of bound. It won't resize the structure so Len will be as before.
func (*BitData) GetBit ¶
GetBit returns true if the bit in position 'index' is 1, false otherwise. It returns an error if something has gone wrong
func (*BitData) GetDifferentPrefix ¶
GetDifferentPrefix ,given another pointer to a BitData, returns a new BitData containing the prefix that is not equal between the two BitDatas. If something goes wrong, returns a nil pointer and an error.
func (*BitData) GetDifferentSuffix ¶
GetDifferentSuffix ,given another pointer to a BitData, returns a new BitData containing the suffix that is not equal between the two BitDatas. If something goes wrong, returns a nil pointer and an error.
func (*BitData) GetFirstLBits ¶
GetFirstLBits return the first l bits of a BitData
func (*BitData) Select1 ¶
Select1 (B,i) with 1 <= i <= n returns the position in B of the i-th occurrence of 1.
type ErrInvalidPosition ¶
type ErrInvalidPosition struct {
// contains filtered or unexported fields
}
ErrInvalidPosition is returned when you are trying to access to an invalid position
func (*ErrInvalidPosition) Error ¶
func (e *ErrInvalidPosition) Error() string