Documentation ¶
Index ¶
- Variables
- func BitIsNotSet(buf []byte, i int) bool
- func BitIsSet(buf []byte, i int) bool
- func BitmapAnd(left, right []byte, lOffset, rOffset int64, out []byte, outOffset int64, ...)
- func BitmapAndAlloc(mem memory.Allocator, left, right []byte, lOffset, rOffset int64, ...) *memory.Buffer
- func BitmapAndNot(left, right []byte, lOffset, rOffset int64, out []byte, outOffset int64, ...)
- func BitmapAndNotAlloc(mem memory.Allocator, left, right []byte, lOffset, rOffset int64, ...) *memory.Buffer
- func BitmapEquals(left, right []byte, lOffset, rOffset int64, length int64) bool
- func BitmapOp(op bitOp, left, right []byte, lOffset, rOffset int64, out []byte, ...)
- func BitmapOpAlloc(mem memory.Allocator, op bitOp, left, right []byte, lOffset, rOffset int64, ...) *memory.Buffer
- func BitmapOr(left, right []byte, lOffset, rOffset int64, out []byte, outOffset int64, ...)
- func BitmapOrAlloc(mem memory.Allocator, left, right []byte, lOffset, rOffset int64, ...) *memory.Buffer
- func BitmapXor(left, right []byte, lOffset, rOffset int64, out []byte, outOffset int64, ...)
- func BitmapXorAlloc(mem memory.Allocator, left, right []byte, lOffset, rOffset int64, ...) *memory.Buffer
- func BytesForBits(bits int64) int64
- func CeilByte(size int) int
- func CeilByte64(size int64) int64
- func ClearBit(buf []byte, i int)
- func CopyBitmap(src []byte, srcOffset, length int, dst []byte, dstOffset int)
- func CountSetBits(buf []byte, offset, n int) int
- func InvertBitmap(src []byte, srcOffset, length int, dst []byte, dstOffset int)
- func IsMultipleOf64(v int64) bool
- func IsMultipleOf8(v int64) bool
- func NextPowerOf2(x int) int
- func SetBit(buf []byte, i int)
- func SetBitTo(buf []byte, i int, val bool)
- func SetBitsTo(bits []byte, startOffset, length int64, areSet bool)
- func VisitWordsAndWrite(args []Bitmap, out []Bitmap, visitor func(in, out []uint64)) error
- type Bitmap
- type BitmapReader
- type BitmapWordReader
- type BitmapWordWriter
- type BitmapWriter
- type OptionalBitIndexer
Constants ¶
This section is empty.
Variables ¶
var ( BitMask = [8]byte{1, 2, 4, 8, 16, 32, 64, 128} FlippedBitMask = [8]byte{254, 253, 251, 247, 239, 223, 191, 127} )
var ( // PrecedingBitmask is a convenience set of values as bitmasks for checking // prefix bits of a byte PrecedingBitmask = [8]byte{0, 1, 3, 7, 15, 31, 63, 127} // TrailingBitmask is the bitwise complement version of kPrecedingBitmask TrailingBitmask = [8]byte{255, 254, 252, 248, 240, 224, 192, 128} )
Functions ¶
func BitIsNotSet ¶
BitIsNotSet returns true if the bit at index i in buf is not set (0).
func BitmapAndAlloc ¶
func BitmapAndNot ¶
func BitmapAndNotAlloc ¶
func BitmapEquals ¶
func BitmapOpAlloc ¶
func BitmapOrAlloc ¶
func BitmapXorAlloc ¶
func BytesForBits ¶
func CeilByte64 ¶
CeilByte64 rounds size to the next multiple of 8.
func CopyBitmap ¶
CopyBitmap copies the bitmap indicated by src, starting at bit offset srcOffset, and copying length bits into dst, starting at bit offset dstOffset.
func CountSetBits ¶
CountSetBits counts the number of 1's in buf up to n bits.
func InvertBitmap ¶
InvertBitmap copies a bit range of a bitmap, inverting it as it copies over into the destination.
func IsMultipleOf64 ¶
IsMultipleOf64 returns whether v is a multiple of 64
func IsMultipleOf8 ¶
IsMultipleOf8 returns whether v is a multiple of 8.
func SetBitsTo ¶
SetBitsTo is a convenience function to quickly set or unset all the bits in a bitmap starting at startOffset for length bits.
func VisitWordsAndWrite ¶
VisitWordsAndWrite visits words of bits from each input bitmap and collects outputs to a slice of output Bitmaps.
All bitmaps must have identical lengths. The first bit in a visited bitmap may be offset within the first visited word, but words will otherwise contain densely packed bits loaded from the bitmap. That offset within the first word is returned.
NOTE: this function is efficient on 3+ sufficiently large bitmaps. It also has a large prolog/epilog overhead and should be used carefully in other cases. For 2 or fewer bitmaps, and/or smaller bitmaps, try BitmapReader and or other utilities.
Types ¶
type BitmapReader ¶
type BitmapReader struct {
// contains filtered or unexported fields
}
BitmapReader is a simple bitmap reader for a byte slice.
func NewBitmapReader ¶
func NewBitmapReader(bitmap []byte, offset, length int) *BitmapReader
NewBitmapReader creates and returns a new bitmap reader for the given bitmap
func (*BitmapReader) Len ¶
func (b *BitmapReader) Len() int
Len returns the total number of bits in the bitmap
func (*BitmapReader) Next ¶
func (b *BitmapReader) Next()
Next advances the reader to the next bit in the bitmap.
func (*BitmapReader) NotSet ¶
func (b *BitmapReader) NotSet() bool
NotSet returns true if the current bit is not set
func (*BitmapReader) Pos ¶
func (b *BitmapReader) Pos() int
Pos returns the current bit position in the bitmap that the reader is looking at
func (*BitmapReader) Set ¶
func (b *BitmapReader) Set() bool
Set returns true if the current bit is set
type BitmapWordReader ¶
type BitmapWordReader struct {
// contains filtered or unexported fields
}
BitmapWordReader is a reader for bitmaps that reads a word at a time (a word being an 8 byte uint64) and then provides functions to grab the individual trailing bytes after the last word
func NewBitmapWordReader ¶
func NewBitmapWordReader(bitmap []byte, offset, length int) *BitmapWordReader
NewBitmapWordReader sets up a word reader, calculates the number of trailing bits and number of trailing bytes, along with the number of words.
func (*BitmapWordReader) NextTrailingByte ¶
func (bm *BitmapWordReader) NextTrailingByte() (val byte, validBits int)
NextTrailingByte returns the next trailing byte of the bitmap after the last word along with the number of valid bits in that byte. When validBits < 8, that is the last byte.
If the bitmap ends on a byte alignment, then the last byte can also return 8 valid bits. Thus the TrailingBytes function should be used to know how many trailing bytes to read.
func (*BitmapWordReader) NextWord ¶
func (bm *BitmapWordReader) NextWord() uint64
NextWord returns the next full word read from the bitmap, should not be called if Words() is 0 as it will step outside of the bounds of the bitmap slice and panic.
We don't perform the bounds checking in order to improve performance.
func (*BitmapWordReader) TrailingBytes ¶
func (bm *BitmapWordReader) TrailingBytes() int
func (*BitmapWordReader) Words ¶
func (bm *BitmapWordReader) Words() int
type BitmapWordWriter ¶
type BitmapWordWriter struct {
// contains filtered or unexported fields
}
BitmapWordWriter is a bitmap writer for writing a full word at a time (a word being a uint64). After the last full word is written, PutNextTrailingByte can be used to write the remaining trailing bytes.
func NewBitmapWordWriter ¶
func NewBitmapWordWriter(bitmap []byte, start, len int) *BitmapWordWriter
NewBitmapWordWriter initializes a new bitmap word writer which will start writing into the byte slice at bit offset start, expecting to write len bits.
func (*BitmapWordWriter) PutNextTrailingByte ¶
func (bm *BitmapWordWriter) PutNextTrailingByte(b byte, validBits int)
PutNextTrailingByte writes the number of bits indicated by validBits from b to the bitmap.
func (*BitmapWordWriter) PutNextWord ¶
func (bm *BitmapWordWriter) PutNextWord(word uint64)
PutNextWord writes the given word to the bitmap, potentially splitting across two adjacent words.
type BitmapWriter ¶
type BitmapWriter struct {
// contains filtered or unexported fields
}
BitmapWriter is a simple writer for writing bitmaps to byte slices
func NewBitmapWriter ¶
func NewBitmapWriter(bitmap []byte, start, length int) *BitmapWriter
NewBitmapWriter returns a sequential bitwise writer that preserves surrounding bit values as it writes.
func (*BitmapWriter) AppendBools ¶
func (b *BitmapWriter) AppendBools(in []bool) int
AppendBools writes a series of booleans to the bitmapwriter and returns the number of remaining bytes left in the buffer for writing.
func (*BitmapWriter) Clear ¶
func (b *BitmapWriter) Clear()
func (*BitmapWriter) Finish ¶
func (b *BitmapWriter) Finish()
Finish flushes the final byte out to the byteslice in case it was not already on a byte aligned boundary.
func (*BitmapWriter) Next ¶
func (b *BitmapWriter) Next()
Next increments the writer to the next bit for writing.
func (*BitmapWriter) Pos ¶
func (b *BitmapWriter) Pos() int
func (*BitmapWriter) Reset ¶
func (b *BitmapWriter) Reset(start, length int)
Reset resets the position and view of the slice to restart writing a bitmap to the same byte slice.
func (*BitmapWriter) Set ¶
func (b *BitmapWriter) Set()
type OptionalBitIndexer ¶
OptionalBitIndexer is a convenience wrapper for getting bits from a bitmap which may or may not be nil.
func (*OptionalBitIndexer) GetBit ¶
func (b *OptionalBitIndexer) GetBit(i int) bool