@@ -988,6 +988,12 @@ class VlqHexDecoder {
988
988
}
989
989
class RoaringBitmap {
990
990
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.
991
997
const strdecoded = atob ( str ) ;
992
998
const u8array = new Uint8Array ( strdecoded . length ) ;
993
999
for ( let j = 0 ; j < strdecoded . length ; ++ j ) {
@@ -1053,6 +1059,13 @@ class RoaringBitmap {
1053
1059
contains ( keyvalue ) {
1054
1060
const key = keyvalue >> 16 ;
1055
1061
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.
1056
1069
let left = 0 ;
1057
1070
let right = this . keys . length - 1 ;
1058
1071
while ( left <= right ) {
@@ -1076,6 +1089,11 @@ class RoaringBitmapRun {
1076
1089
this . array = array ;
1077
1090
}
1078
1091
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.
1079
1097
let left = 0 ;
1080
1098
let right = this . runcount - 1 ;
1081
1099
while ( left <= right ) {
@@ -1100,6 +1118,11 @@ class RoaringBitmapArray {
1100
1118
this . array = array ;
1101
1119
}
1102
1120
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.
1103
1126
let left = 0 ;
1104
1127
let right = this . cardinality - 1 ;
1105
1128
while ( left <= right ) {
0 commit comments