Skip to content

Commit 826d023

Browse files
committed
rustdoc-search: add descriptive comments to bitmap class
1 parent 3fbcc1f commit 826d023

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Diff for: src/librustdoc/html/static/js/search.js

+23
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,12 @@ class VlqHexDecoder {
988988
}
989989
class RoaringBitmap {
990990
constructor(str) {
991+
// https://github.com/RoaringBitmap/RoaringFormatSpec
992+
//
993+
// Roaring bitmaps are used for flags that can be kept in their
994+
// compressed form, even when loaded into memory. This decoder
995+
// turns the containers into objects, but uses byte array
996+
// slices of the original format for the data payload.
991997
const strdecoded = atob(str);
992998
const u8array = new Uint8Array(strdecoded.length);
993999
for (let j = 0; j < strdecoded.length; ++j) {
@@ -1053,6 +1059,13 @@ class RoaringBitmap {
10531059
contains(keyvalue) {
10541060
const key = keyvalue >> 16;
10551061
const value = keyvalue & 0xFFFF;
1062+
// Binary search algorithm copied from
1063+
// https://en.wikipedia.org/wiki/Binary_search#Procedure
1064+
//
1065+
// Format is required by specification to be sorted.
1066+
// Because keys are 16 bits and unique, length can't be
1067+
// bigger than 2**16, and because we have 32 bits of safe int,
1068+
// left + right can't overflow.
10561069
let left = 0;
10571070
let right = this.keys.length - 1;
10581071
while (left <= right) {
@@ -1076,6 +1089,11 @@ class RoaringBitmapRun {
10761089
this.array = array;
10771090
}
10781091
contains(value) {
1092+
// Binary search algorithm copied from
1093+
// https://en.wikipedia.org/wiki/Binary_search#Procedure
1094+
//
1095+
// Since runcount is stored as 16 bits, left + right
1096+
// can't overflow.
10791097
let left = 0;
10801098
let right = this.runcount - 1;
10811099
while (left <= right) {
@@ -1100,6 +1118,11 @@ class RoaringBitmapArray {
11001118
this.array = array;
11011119
}
11021120
contains(value) {
1121+
// Binary search algorithm copied from
1122+
// https://en.wikipedia.org/wiki/Binary_search#Procedure
1123+
//
1124+
// Since cardinality can't be higher than 4096, left + right
1125+
// cannot overflow.
11031126
let left = 0;
11041127
let right = this.cardinality - 1;
11051128
while (left <= right) {

0 commit comments

Comments
 (0)