gocroaring

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 7 Imported by: 1

README

gocroaring GoDoc Tests (Ubuntu, macOS)

Well-tested Go wrapper for CRoaring (a C/C++ implementation of Roaring Bitmaps)

Roaring bitmaps are used by several important systems:

Roaring bitmaps are found to work well in many important applications:

Use Roaring for bitmap compression whenever possible. Do not use other bitmap compression methods (Wang et al., SIGMOD 2017)

The original java version can be found at https://github.com/RoaringBitmap/RoaringBitmap

There is a native Go version at https://github.com/RoaringBitmap/roaring

This code is licensed under Apache License, Version 2.0 (ASL2.0).

Copyright 2016 by the authors.

Benchmarking

See https://github.com/lemire/gobitmapbenchmark for a comparison between this wrapper and the Go native version.

References
  • Daniel Lemire, Owen Kaser, Nathan Kurz, Luca Deri, Chris O'Hara, François Saint-Jacques, Gregory Ssi-Yan-Kai, Roaring Bitmaps: Implementation of an Optimized Software Library arXiv:1709.07821
  • Samy Chambi, Daniel Lemire, Owen Kaser, Robert Godin, Better bitmap performance with Roaring bitmaps, Software: Practice and Experience Volume 46, Issue 5, pages 709–719, May 2016 http://arxiv.org/abs/1402.6407 This paper used data from http://lemire.me/data/realroaring2014.html
  • Daniel Lemire, Gregory Ssi-Yan-Kai, Owen Kaser, Consistently faster and smaller compressed bitmaps with Roaring, Software: Practice and Experience (accepted in 2016, to appear) http://arxiv.org/abs/1603.06549
Requirements

Go 1.24 or better, and a C compiler (cgo). The CRoaring sources are bundled with the package, so there is nothing else to install:

  • go get github.com/RoaringBitmap/gocroaring

The bundled CRoaring version is reported by gocroaring.CRoaringVersion.

32-bit and 64-bit bitmaps

The package wraps both C APIs. gocroaring.Bitmap stores 32-bit integers and wraps roaring_bitmap_t; gocroaring.Bitmap64 stores 64-bit integers and wraps roaring64_bitmap_t. The two types offer the same operations, with the free functions of the 64-bit type carrying a 64 suffix (Or64, And64, Read64, and so on).

rb := gocroaring.New64()
rb.AddRange(1<<40, 1<<40+1000)
rb.RunOptimize()
fmt.Println(rb.Cardinality(), rb.Contains(1<<40+5))
Memory management

Bitmaps and iterators hold memory allocated by C. That memory is released automatically once the Go value becomes unreachable: we register a cleanup with runtime.AddCleanup rather than a finalizer, which lets the garbage collector reclaim a bitmap in a single cycle instead of two, and makes creating and discarding bitmaps about 20% cheaper than the finalizer-based approach we used previously. You may still call Free to release the C memory eagerly; doing so cancels the cleanup, and calling Free twice is harmless.

Iteration reads values from C in blocks rather than one at a time, so walking a bitmap through Iterator() is more than an order of magnitude faster than paying for a crossing of the Go/C boundary per value. Use NewIterator() when you need to move backwards or seek.

The CRoaring entry points are declared #cgo nocallback (none of them calls back into Go) and, where the function does not keep the buffer it is given, #cgo noescape (so the Go buffers we hand to C are not forced onto the heap). The frozen views are deliberately left out of the noescape list, since they do retain their buffer.

Example

Here is a simplified but complete example:

package main

import (
	"fmt"

	"github.com/RoaringBitmap/gocroaring"
)

func main() {
	// example inspired by https://github.com/fzandona/goroar
	fmt.Println("==roaring==")
	rb1 := gocroaring.New(1, 2, 3, 4, 5, 100, 1000)
	rb1.RunOptimize() // improves compression
	fmt.Println("Cardinality: ", rb1.Cardinality())
	fmt.Println("Contains 3? ", rb1.Contains(3))

	rb2 := gocroaring.New()
	rb2.Add(3, 4, 1000)
	rb2.RunOptimize() // improves compression

	rb1.And(rb2)
	// prints {3,4,1000}
	fmt.Println(rb1)

	rb3 := gocroaring.New(1, 5)
	rb3.Or(rb1)

        // prints 1, 3, 4, 5, 1000
        i := rb3.Iterator()
        for i.HasNext() {
          fmt.Println(i.Next())
        }
        fmt.Println()

	fmt.Println(rb3.ToArray())
	fmt.Println(rb3)

	rb4 := gocroaring.FastOr(rb1, rb2, rb3) // optimized way to compute unions between many bitmaps
	fmt.Println(rb4)

	// next we include an example of serialization
	buf := make([]byte, rb1.SerializedSizeInBytes())
	rb1.Write(buf) // we omit error handling
	newrb, _ := gocroaring.Read(buf)
	if rb1.Equals(newrb) {
		fmt.Println("I wrote the content to a byte stream and read it back.")
	}

	fmt.Println(rb1.Stats()) // show the cardinality and the numbers of each type of container used.
}
Documentation

Current documentation is available at http://godoc.org/github.com/RoaringBitmap/gocroaring

Mailing list/discussion group

https://groups.google.com/forum/#!forum/roaring-bitmaps

Compatibility with Java RoaringBitmap library

You can read bitmaps in Go, Java, C, C++ that have been serialized in Go, Java, C, C++.

Documentation

Overview

Package gocroaring is a wrapper for CRoaring in go. It provides a fast compressed bitmap data structure. See http://roaringbitmap.org for details.

The package exposes two types: Bitmap, which stores 32-bit integers and wraps the roaring_bitmap_t C type, and Bitmap64, which stores 64-bit integers and wraps the roaring64_bitmap_t C type.

Bitmaps hold memory allocated by C. That memory is released automatically once the Go value becomes unreachable (we rely on runtime.AddCleanup), but you may call Free explicitly to release it eagerly.

Index

Constants

View Source
const CRoaringMajor = C.ROARING_VERSION_MAJOR

CRoaringMajor, CRoaringMinor and CRoaringRevision report the version of the bundled CRoaring library.

View Source
const CRoaringMinor = C.ROARING_VERSION_MINOR
View Source
const CRoaringRevision = C.ROARING_VERSION_REVISION
View Source
const CRoaringVersion = C.ROARING_VERSION

CRoaringVersion is the version of the bundled CRoaring library, as a string.

View Source
const Frozen64Alignment = 64

Frozen64Alignment is the alignment that a buffer must have before it can back a 64-bit frozen view. See AlignedBuffer64 and ReadFrozenView64.

View Source
const FrozenAlignment = 32

FrozenAlignment is the alignment that a buffer must have before it can back a frozen view. See AlignedBuffer and ReadFrozenView.

Variables

View Source
var (
	// ErrNotEnoughSpace is returned by the serialization routines when the
	// provided buffer is too small.
	ErrNotEnoughSpace = errors.New("not enough space")
	// ErrEmptyBuffer is returned when a deserialization routine is handed an
	// empty buffer.
	ErrEmptyBuffer = errors.New("empty buffer")
	// ErrDeserialize is returned when a buffer does not contain a valid bitmap.
	ErrDeserialize = errors.New("failed to read roaring bitmap")
	// ErrMisaligned is returned by the frozen view routines when the buffer is
	// not aligned on a FrozenAlignment boundary.
	ErrMisaligned = fmt.Errorf("buffer is not aligned on a %d-byte boundary", FrozenAlignment)
	// ErrNoSuchElement is returned by Select when the rank is out of range.
	ErrNoSuchElement = errors.New("no such element")
)
View Source
var ErrMisaligned64 = fmt.Errorf("buffer is not aligned on a %d-byte boundary", Frozen64Alignment)

ErrMisaligned64 is returned by ReadFrozenView64 when the buffer is not aligned on a Frozen64Alignment boundary.

View Source
var ErrNotShrunken = errors.New("the bitmap must be shrunk to fit before it can be frozen")

ErrNotShrunken is returned by Bitmap64.WriteFrozen when ShrinkToFit has not been called since the last modification of the bitmap.

Functions

func AlignedBuffer added in v1.1.0

func AlignedBuffer(size int) []byte

AlignedBuffer returns a byte slice of the requested size whose first byte is aligned on a FrozenAlignment boundary, as required by ReadFrozenView.

func AlignedBuffer64 added in v1.1.0

func AlignedBuffer64(size int) []byte

AlignedBuffer64 returns a byte slice of the requested size whose first byte is aligned on a Frozen64Alignment boundary, as required by ReadFrozenView64.

func PortableDeserializeSize added in v1.1.0

func PortableDeserializeSize(b []byte) int

PortableDeserializeSize returns how many bytes would be read from b by Read, or zero if b does not start with a valid bitmap.

func PortableDeserializeSize64 added in v1.1.0

func PortableDeserializeSize64(b []byte) int

PortableDeserializeSize64 returns how many bytes would be read from b by Read64, or zero if b does not start with a valid bitmap.

Types

type Bitmap

type Bitmap struct {
	// contains filtered or unexported fields
}

Bitmap is a compressed bitmap of 32-bit integers.

A Bitmap is not safe for concurrent modification.

func And

func And(x1, x2 *Bitmap) *Bitmap

And computes the intersection between two bitmaps and returns the result. This function may panic if the allocation failed.

func AndNot

func AndNot(x1, x2 *Bitmap) *Bitmap

AndNot computes the difference between two bitmaps and returns the result. This function may panic if the allocation failed.

func FastOr

func FastOr(bitmaps ...*Bitmap) *Bitmap

FastOr computes the union between many bitmaps quickly, as opposed to having to call Or repeatedly. This function may panic if the allocation failed.

func FastOrHeap added in v1.1.0

func FastOrHeap(bitmaps ...*Bitmap) *Bitmap

FastOrHeap computes the union between many bitmaps using a heap. It can be faster than FastOr when the bitmaps are numerous and of uneven sizes. This function may panic if the allocation failed.

func FastXor added in v1.1.0

func FastXor(bitmaps ...*Bitmap) *Bitmap

FastXor computes the symmetric difference between many bitmaps quickly, as opposed to having to call Xor repeatedly. This function may panic if the allocation failed.

func Flip

func Flip(bm *Bitmap, rangeStart, rangeEnd uint64) *Bitmap

Flip negates the bits in the given range (i.e., [rangeStart, rangeEnd)) and returns the result. This function may panic if the allocation failed.

func FlipClosed added in v1.1.0

func FlipClosed(bm *Bitmap, rangeStart, rangeEnd uint32) *Bitmap

FlipClosed negates the bits in the given range (i.e., [rangeStart, rangeEnd]) and returns the result. This function may panic if the allocation failed.

func FromRange added in v1.1.0

func FromRange(min, max uint64, step uint32) *Bitmap

FromRange creates a bitmap containing min, min+step, min+2*step... up to but not including max. An empty range yields an empty bitmap. The step must be strictly positive. This function may panic if the allocation failed.

func LazyOr added in v1.1.0

func LazyOr(x1, x2 *Bitmap, bitsetconversion bool) *Bitmap

LazyOr computes the union between two bitmaps, leaving the result in an invalid state until RepairAfterLazy is called on it. Set bitsetconversion to true to eagerly convert containers to bitsets when it might help. This function may panic if the allocation failed.

func LazyXor added in v1.1.0

func LazyXor(x1, x2 *Bitmap) *Bitmap

LazyXor computes the symmetric difference between two bitmaps, leaving the result in an invalid state until RepairAfterLazy is called on it. This function may panic if the allocation failed.

func New added in v0.2.0

func New(x ...uint32) *Bitmap

New creates a new Bitmap with any number of initial values. This function may panic if the allocation failed.

func NewWithCapacity added in v1.1.0

func NewWithCapacity(capacity uint32) *Bitmap

NewWithCapacity creates a new Bitmap with room for the given number of containers, avoiding some reallocations when the bitmap is populated. This function may panic if the allocation failed.

func Or

func Or(x1, x2 *Bitmap) *Bitmap

Or computes the union between two bitmaps and returns the result. This function may panic if the allocation failed.

func Read

func Read(b []byte) (*Bitmap, error)

Read reads a serialized version of the bitmap, in the portable format. The buffer is not retained. If the data comes from an untrusted source, prefer ReadValidated.

func ReadFrozenView added in v0.2.65

func ReadFrozenView(b []byte) (*Bitmap, error)

ReadFrozenView reads a frozen serialized version of the bitmap, as written by WriteFrozen. The result is immutable: attempting to mutate it will fail catastrophically. The buffer must be aligned on a FrozenAlignment boundary (see AlignedBuffer) and its length must be exactly the length that was written. A reference to the buffer is retained for the lifetime of the view.

func ReadNative added in v1.1.0

func ReadNative(b []byte) (*Bitmap, error)

ReadNative reads a bitmap written by WriteNative. The buffer is not retained.

func ReadPortableFrozenView added in v1.1.0

func ReadPortableFrozenView(b []byte) (*Bitmap, error)

ReadPortableFrozenView reads a bitmap written in the portable format (see Write) without copying the container data: the result is a read-only view over b. A reference to the buffer is retained for the lifetime of the view.

func ReadValidated added in v1.1.0

func ReadValidated(b []byte) (*Bitmap, error)

ReadValidated reads a serialized version of the bitmap, in the portable format, and checks its internal consistency. Use it when the data comes from an untrusted source. The deserialization and the validation are performed in a single crossing of the Go/C boundary.

func Xor

func Xor(x1, x2 *Bitmap) *Bitmap

Xor computes the symmetric difference between two bitmaps and returns the result. This function may panic if the allocation failed.

func (*Bitmap) Add

func (rb *Bitmap) Add(x ...uint32)

Add the integer(s) x to the bitmap.

func (*Bitmap) AddBulk added in v1.1.0

func (rb *Bitmap) AddBulk(ctx *BulkContext, x uint32)

AddBulk adds the integer x to the bitmap, using ctx to remember the last container visited. Values should be provided in ascending order.

func (*Bitmap) AddChecked added in v1.1.0

func (rb *Bitmap) AddChecked(x uint32) bool

AddChecked adds the integer x to the bitmap and reports whether a new value was actually added.

func (*Bitmap) AddOffset added in v1.1.0

func (rb *Bitmap) AddOffset(offset int64) *Bitmap

AddOffset returns a copy of the bitmap with the given (possibly negative) offset added to every value. Values that fall outside the 32-bit range are dropped. This function may panic if the allocation failed.

func (*Bitmap) AddRange added in v0.3.0

func (rb *Bitmap) AddRange(min, max uint64)

AddRange adds all values in the range [min, max).

func (*Bitmap) AddRangeClosed added in v1.1.0

func (rb *Bitmap) AddRangeClosed(min, max uint32)

AddRangeClosed adds all values in the range [min, max].

func (*Bitmap) And

func (rb *Bitmap) And(x2 *Bitmap)

And computes the intersection between two bitmaps and stores the result in the current bitmap.

func (*Bitmap) AndCardinality added in v0.2.7

func (rb *Bitmap) AndCardinality(x2 *Bitmap) uint64

AndCardinality computes the size of the intersection between two bitmaps.

func (*Bitmap) AndNot

func (rb *Bitmap) AndNot(x2 *Bitmap)

AndNot computes the difference between two bitmaps and stores the result in the current bitmap.

func (*Bitmap) AndNotCardinality added in v0.2.7

func (rb *Bitmap) AndNotCardinality(x2 *Bitmap) uint64

AndNotCardinality computes the size of the difference between two bitmaps.

func (*Bitmap) Assign added in v0.3.0

func (rb *Bitmap) Assign(x2 *Bitmap) bool

Assign copies x2 over rb, returning false if the copy failed.

func (*Bitmap) Cardinality added in v0.2.0

func (rb *Bitmap) Cardinality() uint64

Cardinality returns the number of integers contained in the bitmap.

func (*Bitmap) Clear added in v0.2.9

func (rb *Bitmap) Clear()

Clear removes all elements from the bitmap.

func (*Bitmap) Clone

func (rb *Bitmap) Clone() *Bitmap

Clone creates a copy of the Bitmap. This function may panic if the allocation failed.

func (*Bitmap) Contains

func (rb *Bitmap) Contains(x uint32) bool

Contains returns true if the integer is contained in the bitmap.

func (*Bitmap) ContainsBulk added in v1.1.0

func (rb *Bitmap) ContainsBulk(ctx *BulkContext, x uint32) bool

ContainsBulk reports whether the integer x is in the bitmap, using ctx to remember the last container visited. Values should be provided in ascending order.

func (*Bitmap) ContainsRange added in v0.3.0

func (rb *Bitmap) ContainsRange(x, y uint64) bool

ContainsRange returns true if all the integers in the range [x, y) are contained in the bitmap.

func (*Bitmap) ContainsRangeClosed added in v1.1.0

func (rb *Bitmap) ContainsRangeClosed(x, y uint32) bool

ContainsRangeClosed returns true if all the integers in the range [x, y] are contained in the bitmap.

func (*Bitmap) Equals

func (rb *Bitmap) Equals(o interface{}) bool

Equals returns true if the two bitmaps contain the same integers.

func (*Bitmap) Flip

func (rb *Bitmap) Flip(rangeStart, rangeEnd uint64)

Flip negates the bits in the given range (i.e., [rangeStart, rangeEnd)): any integer present in this range and in the bitmap is removed, and any integer in the range that was absent is added.

func (*Bitmap) FlipClosed added in v1.1.0

func (rb *Bitmap) FlipClosed(rangeStart, rangeEnd uint32)

FlipClosed negates the bits in the given range (i.e., [rangeStart, rangeEnd]).

func (*Bitmap) Free added in v0.4.0

func (rb *Bitmap) Free()

Free releases the memory held by the bitmap. Using the bitmap afterwards is a mistake. Calling Free more than once is harmless.

func (*Bitmap) FrozenSizeInBytes added in v0.2.65

func (rb *Bitmap) FrozenSizeInBytes() int

FrozenSizeInBytes computes the frozen serialized size in bytes.

func (*Bitmap) GetCardinality

func (rb *Bitmap) GetCardinality() uint64

GetCardinality returns the number of integers contained in the bitmap.

func (*Bitmap) GetCopyOnWrite added in v1.1.0

func (rb *Bitmap) GetCopyOnWrite() bool

GetCopyOnWrite reports whether the bitmap uses copy-on-write containers.

func (*Bitmap) GetIndex added in v1.1.0

func (rb *Bitmap) GetIndex(x uint32) int64

GetIndex returns the index of x in the bitmap, or -1 if x is not present. Unlike Rank, it distinguishes a missing value from a value of rank zero.

func (*Bitmap) InternalValidate added in v1.1.0

func (rb *Bitmap) InternalValidate() error

InternalValidate performs internal consistency checks. It is useful after deserializing bitmaps from untrusted sources. It returns nil if the bitmap is consistent, and an error describing the problem otherwise.

func (*Bitmap) Intersect added in v0.2.7

func (rb *Bitmap) Intersect(x2 *Bitmap) bool

Intersect checks whether the two bitmaps intersect.

func (*Bitmap) IntersectWithRange added in v1.1.0

func (rb *Bitmap) IntersectWithRange(x, y uint64) bool

IntersectWithRange checks whether the bitmap intersects the range [x, y).

func (*Bitmap) IsEmpty

func (rb *Bitmap) IsEmpty() bool

IsEmpty returns true if the Bitmap is empty (it is faster than doing Cardinality() == 0).

func (*Bitmap) IsStrictSubset added in v1.1.0

func (rb *Bitmap) IsStrictSubset(x2 *Bitmap) bool

IsStrictSubset returns true if every integer of rb is also in x2 and the two bitmaps differ.

func (*Bitmap) IsSubset added in v1.1.0

func (rb *Bitmap) IsSubset(x2 *Bitmap) bool

IsSubset returns true if every integer of rb is also in x2.

func (*Bitmap) Iterate added in v1.1.0

func (rb *Bitmap) Iterate(cb func(x uint32) bool)

Iterate calls cb with every integer in the bitmap, in sorted order, stopping early if cb returns false.

func (*Bitmap) Iterator added in v0.2.3

func (rb *Bitmap) Iterator() IntIterable

Iterator creates a new IntIterable to iterate over the integers contained in the bitmap, in sorted order. This function may panic if the allocation failed.

func (*Bitmap) JaccardIndex added in v0.2.7

func (rb *Bitmap) JaccardIndex(x2 *Bitmap) float64

JaccardIndex computes the Jaccard index between two bitmaps.

func (*Bitmap) LazyOrInplace added in v1.1.0

func (rb *Bitmap) LazyOrInplace(x2 *Bitmap, bitsetconversion bool)

LazyOrInplace computes the union with x2 in place, leaving the bitmap in an invalid state until RepairAfterLazy is called. Set bitsetconversion to true to eagerly convert containers to bitsets when it might help.

func (*Bitmap) LazyXorInplace added in v1.1.0

func (rb *Bitmap) LazyXorInplace(x2 *Bitmap)

LazyXorInplace computes the symmetric difference with x2 in place, leaving the bitmap in an invalid state until RepairAfterLazy is called.

func (*Bitmap) Maximum added in v0.2.4

func (rb *Bitmap) Maximum() uint32

Maximum returns the largest of the integers contained in the bitmap, or 0 if the bitmap is empty.

func (*Bitmap) Minimum added in v0.2.4

func (rb *Bitmap) Minimum() uint32

Minimum returns the smallest of the integers contained in the bitmap, or math.MaxUint32 if the bitmap is empty.

func (*Bitmap) NativeSerializedSizeInBytes added in v1.1.0

func (rb *Bitmap) NativeSerializedSizeInBytes() int

NativeSerializedSizeInBytes computes the serialized size in bytes of the Bitmap, using the non-portable native format. The native format is not compatible with the Java and Go implementations; prefer the portable format unless you know what you are doing.

func (*Bitmap) NewIterator added in v1.1.0

func (rb *Bitmap) NewIterator() *Iterator

NewIterator returns an iterator positioned on the smallest value of the bitmap. This function may panic if the allocation failed.

func (*Bitmap) Or

func (rb *Bitmap) Or(x2 *Bitmap)

Or computes the union between two bitmaps and stores the result in the current bitmap.

func (*Bitmap) OrCardinality added in v0.2.7

func (rb *Bitmap) OrCardinality(x2 *Bitmap) uint64

OrCardinality computes the size of the union between two bitmaps.

func (*Bitmap) Printf

func (rb *Bitmap) Printf()

Printf writes a description of the bitmap to stdout.

func (*Bitmap) RangeCardinality added in v1.1.0

func (rb *Bitmap) RangeCardinality(min, max uint64) uint64

RangeCardinality returns the number of integers in the bitmap that fall in the range [min, max).

func (*Bitmap) RangeCardinalityClosed added in v1.1.0

func (rb *Bitmap) RangeCardinalityClosed(min, max uint32) uint64

RangeCardinalityClosed returns the number of integers in the bitmap that fall in the range [min, max].

func (*Bitmap) RangeToArray added in v1.1.0

func (rb *Bitmap) RangeToArray(offset, limit uint64) []uint32

RangeToArray returns at most limit integers from the bitmap, in sorted order, starting at the given offset (a rank, not a value).

func (*Bitmap) Rank added in v0.2.4

func (rb *Bitmap) Rank(x uint32) uint64

Rank returns the number of values smaller or equal to x.

func (*Bitmap) RankMany added in v1.1.0

func (rb *Bitmap) RankMany(vals []uint32) []uint64

RankMany returns the rank of each value in vals. The values must be sorted in ascending order. It is faster than calling Rank repeatedly.

func (*Bitmap) Remove

func (rb *Bitmap) Remove(x uint32)

Remove the integer x from the bitmap.

func (*Bitmap) RemoveChecked added in v1.1.0

func (rb *Bitmap) RemoveChecked(x uint32) bool

RemoveChecked removes the integer x from the bitmap and reports whether a value was actually removed.

func (*Bitmap) RemoveMany added in v1.1.0

func (rb *Bitmap) RemoveMany(x ...uint32)

RemoveMany removes the integer(s) x from the bitmap.

func (*Bitmap) RemoveRange added in v0.3.0

func (rb *Bitmap) RemoveRange(min, max uint64)

RemoveRange removes all values in the range [min, max).

func (*Bitmap) RemoveRangeClosed added in v1.1.0

func (rb *Bitmap) RemoveRangeClosed(min, max uint32)

RemoveRangeClosed removes all values in the range [min, max].

func (*Bitmap) RemoveRunCompression

func (rb *Bitmap) RemoveRunCompression() bool

RemoveRunCompression removes run-length encoding even when it is more space efficient; it returns whether a change was applied.

func (*Bitmap) RepairAfterLazy added in v1.1.0

func (rb *Bitmap) RepairAfterLazy()

RepairAfterLazy restores a bitmap produced by the lazy operations to a valid state. It must be called before any other operation.

func (*Bitmap) ReverseIterator added in v1.1.0

func (rb *Bitmap) ReverseIterator() *Iterator

ReverseIterator returns an iterator positioned on the largest value of the bitmap, meant to be walked with Previous. This function may panic if the allocation failed.

func (*Bitmap) RunOptimize

func (rb *Bitmap) RunOptimize() bool

RunOptimize improves the compression of the bitmap (call this after populating a new bitmap); it returns true if the bitmap was modified.

func (*Bitmap) Select added in v0.2.4

func (rb *Bitmap) Select(rank uint32) (uint32, error)

Select returns the element having the designated rank, if it exists.

func (*Bitmap) SerializedSizeInBytes added in v0.2.0

func (rb *Bitmap) SerializedSizeInBytes() int

SerializedSizeInBytes computes the serialized size in bytes of the Bitmap, using the portable format.

func (*Bitmap) SetCopyOnWrite added in v1.1.0

func (rb *Bitmap) SetCopyOnWrite(cow bool)

SetCopyOnWrite turns copy-on-write on or off. Copy-on-write saves memory and avoids copies, but it requires more care in a threaded context. If you enable it, enable it on all of your bitmaps: mixing bitmaps with and without copy-on-write is unsafe.

func (*Bitmap) ShrinkToFit added in v1.1.0

func (rb *Bitmap) ShrinkToFit() int

ShrinkToFit releases unused memory and returns how many bytes were freed.

func (*Bitmap) Stats added in v0.2.0

func (rb *Bitmap) Stats() map[string]uint64

Stats returns some statistics about the roaring bitmap.

func (*Bitmap) StatsStruct added in v0.3.0

func (rb *Bitmap) StatsStruct() Statistics

StatsStruct is the same as Stats but returns a typed struct. See https://github.com/RoaringBitmap/roaring/pull/73 for the rationale.

func (*Bitmap) String

func (rb *Bitmap) String() string

String creates a string representation of the Bitmap.

func (*Bitmap) ToArray

func (rb *Bitmap) ToArray() []uint32

ToArray creates a new slice containing all of the integers stored in the Bitmap in sorted order.

func (*Bitmap) ToBytes added in v1.1.0

func (rb *Bitmap) ToBytes() []byte

ToBytes returns a serialized version of this bitmap, using the portable format.

func (*Bitmap) ToDenseBitset added in v1.1.0

func (rb *Bitmap) ToDenseBitset() ([]uint64, error)

ToDenseBitset converts the bitmap to an uncompressed bitset, returned as a slice of 64-bit words in little-endian bit order: value x is present when bit x%64 of word x/64 is set. Beware that the result can be large: a bitmap containing a single large value produces a slice proportional to that value.

func (*Bitmap) Write

func (rb *Bitmap) Write(b []byte) error

Write writes a serialized version of this bitmap to b, using the portable format. The buffer must be at least SerializedSizeInBytes long.

func (*Bitmap) WriteFrozen added in v0.2.65

func (rb *Bitmap) WriteFrozen(b []byte) error

WriteFrozen writes a serialized version of the bitmap to b in the frozen format. The buffer must be at least FrozenSizeInBytes long. The frozen format is endian-sensitive and version-specific; it is meant for fast reloading of data you produced yourself, not for interchange.

func (*Bitmap) WriteNative added in v1.1.0

func (rb *Bitmap) WriteNative(b []byte) error

WriteNative writes a serialized version of this bitmap to b, using the non-portable native format.

func (*Bitmap) Xor

func (rb *Bitmap) Xor(x2 *Bitmap)

Xor computes the symmetric difference between two bitmaps and stores the result in the current bitmap.

func (*Bitmap) XorCardinality added in v0.2.7

func (rb *Bitmap) XorCardinality(x2 *Bitmap) uint64

XorCardinality computes the size of the symmetric difference between two bitmaps.

type Bitmap64 added in v1.1.0

type Bitmap64 struct {
	// contains filtered or unexported fields
}

Bitmap64 is a compressed bitmap of 64-bit integers.

A Bitmap64 is not safe for concurrent modification.

func And64 added in v1.1.0

func And64(x1, x2 *Bitmap64) *Bitmap64

And64 computes the intersection between two bitmaps and returns the result. This function may panic if the allocation failed.

func AndNot64 added in v1.1.0

func AndNot64(x1, x2 *Bitmap64) *Bitmap64

AndNot64 computes the difference between two bitmaps and returns the result. This function may panic if the allocation failed.

func Flip64 added in v1.1.0

func Flip64(bm *Bitmap64, rangeStart, rangeEnd uint64) *Bitmap64

Flip64 negates the bits in the given range (i.e., [rangeStart, rangeEnd)) and returns the result. This function may panic if the allocation failed.

func FlipClosed64 added in v1.1.0

func FlipClosed64(bm *Bitmap64, rangeStart, rangeEnd uint64) *Bitmap64

FlipClosed64 negates the bits in the given range (i.e., [rangeStart, rangeEnd]) and returns the result. This function may panic if the allocation failed.

func FromRange64 added in v1.1.0

func FromRange64(min, max, step uint64) *Bitmap64

FromRange64 creates a bitmap containing min, min+step, min+2*step... up to but not including max. An empty range yields an empty bitmap. The step must be strictly positive. This function may panic if the allocation failed.

func MoveFrom32 added in v1.1.0

func MoveFrom32(from *Bitmap) *Bitmap64

MoveFrom32 builds a 64-bit bitmap by moving the containers out of a 32-bit bitmap. This avoids copying the container data, but it leaves the source bitmap empty.

The containers are taken without regard for copy-on-write sharing, so do not use it on a bitmap whose containers are shared with another one (that is, a bitmap that has copy-on-write enabled and has been cloned). Clone first if you need the source intact. This function may panic if the allocation failed.

func New64 added in v1.1.0

func New64(x ...uint64) *Bitmap64

New64 creates a new Bitmap64 with any number of initial values. This function may panic if the allocation failed.

func Or64 added in v1.1.0

func Or64(x1, x2 *Bitmap64) *Bitmap64

Or64 computes the union between two bitmaps and returns the result. This function may panic if the allocation failed.

func Read64 added in v1.1.0

func Read64(b []byte) (*Bitmap64, error)

Read64 reads a serialized version of the bitmap, in the portable format. The buffer is not retained. If the data comes from an untrusted source, prefer ReadValidated64.

func ReadFrozenView64 added in v1.1.0

func ReadFrozenView64(b []byte) (*Bitmap64, error)

ReadFrozenView64 reads a frozen serialized version of the bitmap, as written by Bitmap64.WriteFrozen. The result is immutable: attempting to mutate it will fail catastrophically. The buffer must be aligned on a Frozen64Alignment boundary (see AlignedBuffer64) and its length must be exactly the length that was written. A reference to the buffer is retained for the lifetime of the view.

func ReadPortableFrozenView64 added in v1.1.0

func ReadPortableFrozenView64(b []byte) (*Bitmap64, error)

ReadPortableFrozenView64 reads a bitmap written in the portable format (see Bitmap64.Write) without copying the container data: the result is a read-only view over b. A reference to the buffer is retained for the lifetime of the view. It fails on big-endian systems, where the portable format cannot be viewed in place.

func ReadValidated64 added in v1.1.0

func ReadValidated64(b []byte) (*Bitmap64, error)

ReadValidated64 reads a serialized version of the bitmap, in the portable format, and checks its internal consistency. Use it when the data comes from an untrusted source. The deserialization and the validation are performed in a single crossing of the Go/C boundary.

func Xor64 added in v1.1.0

func Xor64(x1, x2 *Bitmap64) *Bitmap64

Xor64 computes the symmetric difference between two bitmaps and returns the result. This function may panic if the allocation failed.

func (*Bitmap64) Add added in v1.1.0

func (rb *Bitmap64) Add(x ...uint64)

Add the integer(s) x to the bitmap.

func (*Bitmap64) AddBulk added in v1.1.0

func (rb *Bitmap64) AddBulk(ctx *BulkContext64, x uint64)

AddBulk adds the integer x to the bitmap, using ctx to remember the last container visited. Values should be provided in ascending order.

func (*Bitmap64) AddChecked added in v1.1.0

func (rb *Bitmap64) AddChecked(x uint64) bool

AddChecked adds the integer x to the bitmap and reports whether a new value was actually added.

func (*Bitmap64) AddOffset added in v1.1.0

func (rb *Bitmap64) AddOffset(offset int64) *Bitmap64

AddOffset returns a copy of the bitmap with the given (possibly negative) offset added to every value. Values that fall outside the 64-bit range are dropped. This function may panic if the allocation failed.

func (*Bitmap64) AddRange added in v1.1.0

func (rb *Bitmap64) AddRange(min, max uint64)

AddRange adds all values in the range [min, max).

func (*Bitmap64) AddRangeClosed added in v1.1.0

func (rb *Bitmap64) AddRangeClosed(min, max uint64)

AddRangeClosed adds all values in the range [min, max].

func (*Bitmap64) And added in v1.1.0

func (rb *Bitmap64) And(x2 *Bitmap64)

And computes the intersection between two bitmaps and stores the result in the current bitmap.

func (*Bitmap64) AndCardinality added in v1.1.0

func (rb *Bitmap64) AndCardinality(x2 *Bitmap64) uint64

AndCardinality computes the size of the intersection between two bitmaps.

func (*Bitmap64) AndNot added in v1.1.0

func (rb *Bitmap64) AndNot(x2 *Bitmap64)

AndNot computes the difference between two bitmaps and stores the result in the current bitmap.

func (*Bitmap64) AndNotCardinality added in v1.1.0

func (rb *Bitmap64) AndNotCardinality(x2 *Bitmap64) uint64

AndNotCardinality computes the size of the difference between two bitmaps.

func (*Bitmap64) Assign added in v1.1.0

func (rb *Bitmap64) Assign(x2 *Bitmap64)

Assign copies x2 over rb.

func (*Bitmap64) Cardinality added in v1.1.0

func (rb *Bitmap64) Cardinality() uint64

Cardinality returns the number of integers contained in the bitmap.

func (*Bitmap64) Clear added in v1.1.0

func (rb *Bitmap64) Clear()

Clear removes all elements from the bitmap.

func (*Bitmap64) Clone added in v1.1.0

func (rb *Bitmap64) Clone() *Bitmap64

Clone creates a copy of the Bitmap64. This function may panic if the allocation failed.

func (*Bitmap64) Contains added in v1.1.0

func (rb *Bitmap64) Contains(x uint64) bool

Contains returns true if the integer is contained in the bitmap.

func (*Bitmap64) ContainsBulk added in v1.1.0

func (rb *Bitmap64) ContainsBulk(ctx *BulkContext64, x uint64) bool

ContainsBulk reports whether the integer x is in the bitmap, using ctx to remember the last container visited. Values should be provided in ascending order.

func (*Bitmap64) ContainsRange added in v1.1.0

func (rb *Bitmap64) ContainsRange(x, y uint64) bool

ContainsRange returns true if all the integers in the range [x, y) are contained in the bitmap.

func (*Bitmap64) ContainsRangeClosed added in v1.1.0

func (rb *Bitmap64) ContainsRangeClosed(x, y uint64) bool

ContainsRangeClosed returns true if all the integers in the range [x, y] are contained in the bitmap.

func (*Bitmap64) Equals added in v1.1.0

func (rb *Bitmap64) Equals(o interface{}) bool

Equals returns true if the two bitmaps contain the same integers.

func (*Bitmap64) Flip added in v1.1.0

func (rb *Bitmap64) Flip(rangeStart, rangeEnd uint64)

Flip negates the bits in the given range (i.e., [rangeStart, rangeEnd)).

func (*Bitmap64) FlipClosed added in v1.1.0

func (rb *Bitmap64) FlipClosed(rangeStart, rangeEnd uint64)

FlipClosed negates the bits in the given range (i.e., [rangeStart, rangeEnd]).

func (*Bitmap64) Free added in v1.1.0

func (rb *Bitmap64) Free()

Free releases the memory held by the bitmap. Using the bitmap afterwards is a mistake. Calling Free more than once is harmless.

func (*Bitmap64) FrozenSizeInBytes added in v1.1.0

func (rb *Bitmap64) FrozenSizeInBytes() int

FrozenSizeInBytes computes the frozen serialized size in bytes. ShrinkToFit must have been called since the last modification of the bitmap; otherwise this returns zero.

func (*Bitmap64) GetCardinality added in v1.1.0

func (rb *Bitmap64) GetCardinality() uint64

GetCardinality returns the number of integers contained in the bitmap.

func (*Bitmap64) GetIndex added in v1.1.0

func (rb *Bitmap64) GetIndex(x uint64) int64

GetIndex returns the index of x in the bitmap, or -1 if x is not present. Unlike Rank, it distinguishes a missing value from a value of rank zero.

func (*Bitmap64) InternalValidate added in v1.1.0

func (rb *Bitmap64) InternalValidate() error

InternalValidate performs internal consistency checks. It is useful after deserializing bitmaps from untrusted sources. It returns nil if the bitmap is consistent, and an error describing the problem otherwise.

func (*Bitmap64) Intersect added in v1.1.0

func (rb *Bitmap64) Intersect(x2 *Bitmap64) bool

Intersect checks whether the two bitmaps intersect.

func (*Bitmap64) IntersectWithRange added in v1.1.0

func (rb *Bitmap64) IntersectWithRange(x, y uint64) bool

IntersectWithRange checks whether the bitmap intersects the range [x, y).

func (*Bitmap64) IsEmpty added in v1.1.0

func (rb *Bitmap64) IsEmpty() bool

IsEmpty returns true if the Bitmap64 is empty (it is faster than doing Cardinality() == 0).

func (*Bitmap64) IsStrictSubset added in v1.1.0

func (rb *Bitmap64) IsStrictSubset(x2 *Bitmap64) bool

IsStrictSubset returns true if every integer of rb is also in x2 and the two bitmaps differ.

func (*Bitmap64) IsSubset added in v1.1.0

func (rb *Bitmap64) IsSubset(x2 *Bitmap64) bool

IsSubset returns true if every integer of rb is also in x2.

func (*Bitmap64) Iterate added in v1.1.0

func (rb *Bitmap64) Iterate(cb func(x uint64) bool)

Iterate calls cb with every integer in the bitmap, in sorted order, stopping early if cb returns false.

func (*Bitmap64) Iterator added in v1.1.0

func (rb *Bitmap64) Iterator() IntIterable64

Iterator creates a new IntIterable64 to iterate over the integers contained in the bitmap, in sorted order. This function may panic if the allocation failed.

func (*Bitmap64) JaccardIndex added in v1.1.0

func (rb *Bitmap64) JaccardIndex(x2 *Bitmap64) float64

JaccardIndex computes the Jaccard index between two bitmaps.

func (*Bitmap64) Maximum added in v1.1.0

func (rb *Bitmap64) Maximum() uint64

Maximum returns the largest of the integers contained in the bitmap, or 0 if the bitmap is empty.

func (*Bitmap64) Minimum added in v1.1.0

func (rb *Bitmap64) Minimum() uint64

Minimum returns the smallest of the integers contained in the bitmap, or math.MaxUint64 if the bitmap is empty.

func (*Bitmap64) NewIterator added in v1.1.0

func (rb *Bitmap64) NewIterator() *Iterator64

NewIterator returns an iterator positioned on the smallest value of the bitmap. This function may panic if the allocation failed.

func (*Bitmap64) Or added in v1.1.0

func (rb *Bitmap64) Or(x2 *Bitmap64)

Or computes the union between two bitmaps and stores the result in the current bitmap.

func (*Bitmap64) OrCardinality added in v1.1.0

func (rb *Bitmap64) OrCardinality(x2 *Bitmap64) uint64

OrCardinality computes the size of the union between two bitmaps.

func (*Bitmap64) RangeCardinality added in v1.1.0

func (rb *Bitmap64) RangeCardinality(min, max uint64) uint64

RangeCardinality returns the number of integers in the bitmap that fall in the range [min, max).

func (*Bitmap64) RangeCardinalityClosed added in v1.1.0

func (rb *Bitmap64) RangeCardinalityClosed(min, max uint64) uint64

RangeCardinalityClosed returns the number of integers in the bitmap that fall in the range [min, max].

func (*Bitmap64) Rank added in v1.1.0

func (rb *Bitmap64) Rank(x uint64) uint64

Rank returns the number of values smaller or equal to x.

func (*Bitmap64) Remove added in v1.1.0

func (rb *Bitmap64) Remove(x uint64)

Remove the integer x from the bitmap.

func (*Bitmap64) RemoveBulk added in v1.1.0

func (rb *Bitmap64) RemoveBulk(ctx *BulkContext64, x uint64)

RemoveBulk removes the integer x from the bitmap, using ctx to remember the last container visited. Values should be provided in ascending order.

func (*Bitmap64) RemoveChecked added in v1.1.0

func (rb *Bitmap64) RemoveChecked(x uint64) bool

RemoveChecked removes the integer x from the bitmap and reports whether a value was actually removed.

func (*Bitmap64) RemoveMany added in v1.1.0

func (rb *Bitmap64) RemoveMany(x ...uint64)

RemoveMany removes the integer(s) x from the bitmap.

func (*Bitmap64) RemoveRange added in v1.1.0

func (rb *Bitmap64) RemoveRange(min, max uint64)

RemoveRange removes all values in the range [min, max).

func (*Bitmap64) RemoveRangeClosed added in v1.1.0

func (rb *Bitmap64) RemoveRangeClosed(min, max uint64)

RemoveRangeClosed removes all values in the range [min, max].

func (*Bitmap64) RemoveRunCompression added in v1.1.0

func (rb *Bitmap64) RemoveRunCompression() bool

RemoveRunCompression removes run-length encoding even when it is more space efficient; it returns whether a change was applied.

func (*Bitmap64) ReverseIterator added in v1.1.0

func (rb *Bitmap64) ReverseIterator() *Iterator64

ReverseIterator returns an iterator positioned on the largest value of the bitmap, meant to be walked with Previous. This function may panic if the allocation failed.

func (*Bitmap64) RunOptimize added in v1.1.0

func (rb *Bitmap64) RunOptimize() bool

RunOptimize improves the compression of the bitmap (call this after populating a new bitmap); it returns true if the bitmap was modified.

func (*Bitmap64) Select added in v1.1.0

func (rb *Bitmap64) Select(rank uint64) (uint64, error)

Select returns the element having the designated rank, if it exists.

func (*Bitmap64) SerializedSizeInBytes added in v1.1.0

func (rb *Bitmap64) SerializedSizeInBytes() int

SerializedSizeInBytes computes the serialized size in bytes of the Bitmap64, using the portable format.

func (*Bitmap64) ShrinkToFit added in v1.1.0

func (rb *Bitmap64) ShrinkToFit() int

ShrinkToFit releases unused memory and returns how many bytes were freed.

func (*Bitmap64) Stats added in v1.1.0

func (rb *Bitmap64) Stats() map[string]uint64

Stats returns some statistics about the roaring bitmap.

func (*Bitmap64) StatsStruct added in v1.1.0

func (rb *Bitmap64) StatsStruct() Statistics

StatsStruct returns statistics describing the internal structure of the bitmap.

func (*Bitmap64) String added in v1.1.0

func (rb *Bitmap64) String() string

String creates a string representation of the Bitmap64.

func (*Bitmap64) ToArray added in v1.1.0

func (rb *Bitmap64) ToArray() []uint64

ToArray creates a new slice containing all of the integers stored in the Bitmap64 in sorted order.

func (*Bitmap64) ToBytes added in v1.1.0

func (rb *Bitmap64) ToBytes() []byte

ToBytes returns a serialized version of this bitmap, using the portable format.

func (*Bitmap64) Write added in v1.1.0

func (rb *Bitmap64) Write(b []byte) error

Write writes a serialized version of this bitmap to b, using the portable format. The buffer must be at least SerializedSizeInBytes long.

func (*Bitmap64) WriteFrozen added in v1.1.0

func (rb *Bitmap64) WriteFrozen(b []byte) error

WriteFrozen writes a serialized version of the bitmap to b in the frozen format. ShrinkToFit must have been called since the last modification of the bitmap. The buffer must be at least FrozenSizeInBytes long. The frozen format is endian-sensitive and version-specific; it is meant for fast reloading of data you produced yourself, not for interchange.

func (*Bitmap64) Xor added in v1.1.0

func (rb *Bitmap64) Xor(x2 *Bitmap64)

Xor computes the symmetric difference between two bitmaps and stores the result in the current bitmap.

func (*Bitmap64) XorCardinality added in v1.1.0

func (rb *Bitmap64) XorCardinality(x2 *Bitmap64) uint64

XorCardinality computes the size of the symmetric difference between two bitmaps.

type BulkContext added in v1.1.0

type BulkContext struct {
	// contains filtered or unexported fields
}

BulkContext accelerates repeated accesses to a bitmap when the values are provided in ascending order. A context is tied to the bitmap it was last used with: it must not be reused across bitmaps, and it must be discarded whenever the bitmap is modified by anything other than AddBulk.

func NewBulkContext added in v1.1.0

func NewBulkContext() *BulkContext

NewBulkContext returns a fresh context for use with AddBulk and ContainsBulk.

type BulkContext64 added in v1.1.0

type BulkContext64 struct {
	// contains filtered or unexported fields
}

BulkContext64 accelerates repeated accesses to a Bitmap64 when the values are provided in ascending order. A context is tied to the bitmap it was last used with: it must not be reused across bitmaps, and it must be discarded whenever the bitmap is modified by anything other than AddBulk or RemoveBulk.

func NewBulkContext64 added in v1.1.0

func NewBulkContext64() *BulkContext64

NewBulkContext64 returns a fresh context for use with AddBulk, RemoveBulk and ContainsBulk.

type IntIterable added in v0.2.3

type IntIterable interface {
	HasNext() bool
	Next() uint32
}

IntIterable allows you to iterate over the values in a Bitmap.

type IntIterable64 added in v1.1.0

type IntIterable64 interface {
	HasNext() bool
	Next() uint64
}

IntIterable64 allows you to iterate over the values in a Bitmap64.

type Iterator added in v1.1.0

type Iterator struct {
	// contains filtered or unexported fields
}

Iterator is a full-featured iterator over the values of a Bitmap. Unlike the iterator returned by Bitmap.Iterator, it can move backwards and can seek.

An Iterator points at a value or is exhausted; use HasValue to tell the two apart. It is invalidated by any modification of the underlying bitmap.

func (*Iterator) AdvanceIfNeeded added in v1.1.0

func (i *Iterator) AdvanceIfNeeded(x uint32) bool

AdvanceIfNeeded moves the iterator to the smallest value that is greater than or equal to x, and reports whether it points at a value. The iterator does not move if it already points at such a value.

func (*Iterator) Clone added in v1.1.0

func (i *Iterator) Clone() *Iterator

Clone returns a copy of the iterator, positioned on the same value. This function may panic if the allocation failed.

func (*Iterator) Free added in v1.1.0

func (i *Iterator) Free()

Free releases the memory held by the iterator. Using the iterator afterwards is a mistake. Calling Free more than once is harmless.

func (*Iterator) HasValue added in v1.1.0

func (i *Iterator) HasValue() bool

HasValue reports whether the iterator points at a value.

func (*Iterator) Next added in v1.1.0

func (i *Iterator) Next() bool

Next moves the iterator to the next value and reports whether it points at one.

func (*Iterator) Previous added in v1.1.0

func (i *Iterator) Previous() bool

Previous moves the iterator to the previous value and reports whether it points at one.

func (*Iterator) Read added in v1.1.0

func (i *Iterator) Read(buf []uint32) int

Read fills buf with up to len(buf) values, in ascending order, and returns how many were written. A return value smaller than len(buf) means the iterator is exhausted.

func (*Iterator) ReadBackward added in v1.1.0

func (i *Iterator) ReadBackward(buf []uint32) int

ReadBackward fills buf with up to len(buf) values, in descending order, and returns how many were written.

func (*Iterator) ReadPreviousRanges added in v1.1.0

func (i *Iterator) ReadPreviousRanges(buf []Range) int

ReadPreviousRanges fills buf with up to len(buf) runs of consecutive values, in descending order, and returns how many were written.

func (*Iterator) ReadRanges added in v1.1.0

func (i *Iterator) ReadRanges(buf []Range) int

ReadRanges fills buf with up to len(buf) runs of consecutive values, in ascending order, and returns how many were written.

func (*Iterator) Reset added in v1.1.0

func (i *Iterator) Reset()

Reset repositions the iterator on the smallest value of the bitmap it was created from.

func (*Iterator) ResetToLast added in v1.1.0

func (i *Iterator) ResetToLast()

ResetToLast repositions the iterator on the largest value of the bitmap it was created from.

func (*Iterator) Skip added in v1.1.0

func (i *Iterator) Skip(count uint32) uint32

Skip advances the iterator by count values and returns how many values were actually skipped.

func (*Iterator) SkipBackward added in v1.1.0

func (i *Iterator) SkipBackward(count uint32) uint32

SkipBackward moves the iterator back by count values and returns how many values were actually skipped.

func (*Iterator) Value added in v1.1.0

func (i *Iterator) Value() uint32

Value returns the value the iterator points at. It is meaningless when HasValue is false.

type Iterator64 added in v1.1.0

type Iterator64 struct {
	// contains filtered or unexported fields
}

Iterator64 is a full-featured iterator over the values of a Bitmap64. Unlike the iterator returned by Bitmap64.Iterator, it can move backwards and can seek.

An Iterator64 points at a value or is exhausted; use HasValue to tell the two apart. It is invalidated by any modification of the underlying bitmap.

func (*Iterator64) AdvanceIfNeeded added in v1.1.0

func (i *Iterator64) AdvanceIfNeeded(x uint64) bool

AdvanceIfNeeded moves the iterator to the smallest value that is greater than or equal to x, and reports whether it points at a value. The iterator does not move if it already points at such a value.

func (*Iterator64) Clone added in v1.1.0

func (i *Iterator64) Clone() *Iterator64

Clone returns a copy of the iterator, positioned on the same value. This function may panic if the allocation failed.

func (*Iterator64) Free added in v1.1.0

func (i *Iterator64) Free()

Free releases the memory held by the iterator. Using the iterator afterwards is a mistake. Calling Free more than once is harmless.

func (*Iterator64) HasValue added in v1.1.0

func (i *Iterator64) HasValue() bool

HasValue reports whether the iterator points at a value.

func (*Iterator64) Next added in v1.1.0

func (i *Iterator64) Next() bool

Next moves the iterator to the next value and reports whether it points at one.

func (*Iterator64) Previous added in v1.1.0

func (i *Iterator64) Previous() bool

Previous moves the iterator to the previous value and reports whether it points at one.

func (*Iterator64) Read added in v1.1.0

func (i *Iterator64) Read(buf []uint64) int

Read fills buf with up to len(buf) values, in ascending order, and returns how many were written. A return value smaller than len(buf) means the iterator is exhausted.

func (*Iterator64) ReadBackward added in v1.1.0

func (i *Iterator64) ReadBackward(buf []uint64) int

ReadBackward fills buf with up to len(buf) values, in descending order, and returns how many were written.

func (*Iterator64) ReadPreviousRanges added in v1.1.0

func (i *Iterator64) ReadPreviousRanges(buf []Range64) int

ReadPreviousRanges fills buf with up to len(buf) runs of consecutive values, in descending order, and returns how many were written.

func (*Iterator64) ReadRanges added in v1.1.0

func (i *Iterator64) ReadRanges(buf []Range64) int

ReadRanges fills buf with up to len(buf) runs of consecutive values, in ascending order, and returns how many were written.

func (*Iterator64) Reset added in v1.1.0

func (i *Iterator64) Reset()

Reset repositions the iterator on the smallest value of the bitmap it was created from.

func (*Iterator64) ResetToLast added in v1.1.0

func (i *Iterator64) ResetToLast()

ResetToLast repositions the iterator on the largest value of the bitmap it was created from.

func (*Iterator64) Value added in v1.1.0

func (i *Iterator64) Value() uint64

Value returns the value the iterator points at. It is meaningless when HasValue is false.

type Range added in v1.1.0

type Range struct {
	Min uint32
	Max uint32
}

Range is a closed interval [Min, Max] of 32-bit values.

type Range64 added in v1.1.0

type Range64 struct {
	Min uint64
	Max uint64
}

Range64 is a closed interval [Min, Max] of 64-bit values.

type Statistics added in v0.3.0

type Statistics struct {
	Cardinality uint64
	Containers  uint64

	ArrayContainers      uint64
	ArrayContainerBytes  uint64
	ArrayContainerValues uint64

	BitmapContainers      uint64
	BitmapContainerBytes  uint64
	BitmapContainerValues uint64

	RunContainers      uint64
	RunContainerBytes  uint64
	RunContainerValues uint64

	// MinValue and MaxValue are undefined when Cardinality is zero.
	MinValue uint64
	MaxValue uint64
}

Statistics describes the internal structure of a bitmap.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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