Bitmap

A mutable set of document ordinals, held as one block per 65 536 ordinals.

This is what an index build accumulates: as a segment's documents are walked, the ordinals matching a value go into one of these, and encode turns it into the bytes a sidecar carries. Reading one back is BitmapView, which does not build this at all.

val matching = Bitmap()
matching.add(7)
matching.addAll(100..199)
matching.cardinality // 101
val bytes = matching.encode()

Not thread-safe, and deliberately: one of these belongs to one sidecar build, the same rule the catalog's sketch collector follows. Several may be built at once — a compaction writes more than one segment — but each on its own thread.

Equality is by ordinals, not by representation. A bitmap built by adding values one at a time and one built by a union of two others are equal when they hold the same ordinals, and either is equal to a BitmapView over its own encode. That is the point: the encoding of a set of ordinals is unique, so a comparison of bytes is a comparison of contents, and the tests can assert the strong form.

hashCode walks the ordinals, so it is O(cardinality). Sound rather than fast, which is the right way round for a structure nobody puts in a hash map by design.

Constructors

Link copied to clipboard
constructor()

An empty bitmap.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open override val cardinality: Int

How many ordinals are present.

Link copied to clipboard
open val isEmpty: Boolean

Functions

Link copied to clipboard
fun add(ordinal: Int): Boolean

Adds ordinal. true if it was not already present.

Link copied to clipboard
fun addAll(ordinals: IntRange)

Adds every ordinal in ordinals.

Link copied to clipboard
open fun and(other: ReadableBitmap): Bitmap

The ordinals present in both.

Link copied to clipboard

How many ordinals the two share, without building the intersection.

Link copied to clipboard
open fun andNot(other: ReadableBitmap): Bitmap

The ordinals present here and not in other.

Link copied to clipboard

Removes from this bitmap every ordinal present in other.

Link copied to clipboard

Replaces this bitmap's ordinals with the intersection of it and other.

Link copied to clipboard
fun clear()

Drops every ordinal.

Link copied to clipboard
open fun contains(ordinal: Int): Boolean

Whether ordinal is present. Any Int is a fair question; a negative one is simply absent.

Link copied to clipboard
fun copy(): Bitmap

An independent copy.

Link copied to clipboard
open fun cursor(): BitmapCursor

A walk over every present ordinal, ascending.

Link copied to clipboard
open fun encode(): ByteArray

This bitmap in the layout BitmapFormat describes, canonically encoded.

Link copied to clipboard
open fun encodedByteSize(): Int

The size encode will produce, without producing it.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open fun first(): Int

The smallest ordinal present.

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard

Whether the two share an ordinal, without building the intersection.

Link copied to clipboard
open fun last(): Int

The largest ordinal present.

Link copied to clipboard
open fun or(other: ReadableBitmap): Bitmap

The ordinals present in either.

Link copied to clipboard

Replaces this bitmap's ordinals with the union of it and other.

Link copied to clipboard
open fun rank(ordinal: Int): Int

How many present ordinals are less than or equal to ordinal.

Link copied to clipboard
fun remove(ordinal: Int): Boolean

Removes ordinal. true if it was present.

Link copied to clipboard
fun removeAll(ordinals: IntRange)

Removes every ordinal in ordinals.

Link copied to clipboard
open fun select(index: Int): Int

The index-th smallest ordinal present, counting from zero.

Link copied to clipboard
open override fun toBitmap(): Bitmap

An independent, mutable bitmap holding the same ordinals.

Link copied to clipboard
open fun toIntArray(): IntArray

Every present ordinal, ascending. For tests and for small results; a cursor does not allocate.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
open fun xor(other: ReadableBitmap): Bitmap

The ordinals present in exactly one of the two.

Link copied to clipboard

Replaces this bitmap's ordinals with those present in exactly one of it and other.