bitdata

package
v0.0.0-...-d2f764f Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package bitdata contains types and methods in order to deal with array of bits

Index

Constants

This section is empty.

Variables

View Source
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

func GetLengthInBit(s string) uint64

GetLengthInBit returns the length in bit of the string s.

func GetTotalBitCount

func GetTotalBitCount(strings []string) uint64

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

func GetBitData(s string) (*BitData, error)

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 New

func New(ba bitarray.BitArray, len uint64) *BitData

New returns a pointer to a new BitData structure of the specified size.

func (*BitData) AppendBit

func (s1 *BitData) AppendBit(bit bool) error

AppendBit appends a bit given as a bool to the s1 BitData.

func (*BitData) AppendBits

func (s1 *BitData) AppendBits(s2 *BitData) error

AppendBits appends the bits of a BitData (s2) onto the s1 BitData.

func (*BitData) BitToByte

func (s1 *BitData) BitToByte() ([]byte, error)

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

func (s1 *BitData) BitToString() (string, error)

BitToString returns a decoded string given a BitData. If something has gone wrong it returns a nil string and an error.

func (*BitData) BitToStringOfLengthL

func (s1 *BitData) BitToStringOfLengthL(l uint64) (string, error)

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

func (s1 *BitData) BitToTrimmedString() (string, error)

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

func (s1 *BitData) ClearBit(index uint64) error

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

func (s1 *BitData) GetBit(index uint64) (bool, error)

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

func (s1 *BitData) GetDifferentPrefix(s2 *BitData) (*BitData, error)

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

func (s1 *BitData) GetDifferentSuffix(s2 *BitData) (*BitData, error)

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

func (s1 *BitData) GetFirstLBits(l uint64) (*BitData, error)

GetFirstLBits return the first l bits of a BitData

func (*BitData) Rank1

func (s1 *BitData) Rank1(i uint64) (uint64, error)

Rank1 (B,i) returns the number of 1s in the prefix B[1...i] aka B[0...i-1].

func (*BitData) Select1

func (s1 *BitData) Select1(i uint64) (uint64, error)

Select1 (B,i) with 1 <= i <= n returns the position in B of the i-th occurrence of 1.

func (*BitData) SetBit

func (s1 *BitData) SetBit(index uint64) error

SetBit sets 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) String

func (s1 *BitData) String() string

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

Jump to

Keyboard shortcuts

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