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.
Functions
The ordinals present in both.
How many ordinals the two share, without building the intersection.
The ordinals present here and not in other.
Removes from this bitmap every ordinal present in other.
Replaces this bitmap's ordinals with the intersection of it and other.
A walk over every present ordinal, ascending.
This bitmap in the layout BitmapFormat describes, canonically encoded.
The size encode will produce, without producing it.
Whether the two share an ordinal, without building the intersection.
The ordinals present in either.
Replaces this bitmap's ordinals with the union of it and other.
Every present ordinal, ascending. For tests and for small results; a cursor does not allocate.
The ordinals present in exactly one of the two.
Replaces this bitmap's ordinals with those present in exactly one of it and other.