Bitmap Functions
Bitmaps can be constructed in two ways. The first way is constructed by aggregation function groupBitmap with -State, the other way is to constructed a bitmap from an Array object.
bitmapBuild
Builds a bitmap from an unsigned integer array.
Syntax
Arguments
array– Unsigned integer array.
Example
bitmapToArray
Converts bitmap to an integer array.
Syntax
Arguments
bitmap– Bitmap object.
Example
Result:
bitmapSubsetInRange
Returns the subset of a bitmap with bits within a value interval.
Syntax
Arguments
bitmap– Bitmap object.range_start– Start of the range (inclusive). UInt32.range_end– End of the range (exclusive). UInt32.
Example
Result:
bitmapSubsetLimit
Returns a subset of a bitmap with smallest bit value range_start and at most cardinality_limit elements.
Syntax
Arguments
bitmap– Bitmap object.range_start– Start of the range (inclusive). UInt32.cardinality_limit– Maximum cardinality of the subset. UInt32.
Example
Result:
subBitmap
Returns a subset of the bitmap, starting from position offset. The maximum cardinality of the returned bitmap is cardinality_limit.
Syntax
Arguments
bitmap– The bitmap. Bitmap object.offset– The position of the first element of the subset. UInt32.cardinality_limit– The maximum number of elements in the subset. UInt32.
Example
Result:
bitmapContains
Checks whether the bitmap contains an element.
Arguments
bitmap– Bitmap object.needle– Searched bit value. UInt32.
Returned values
Example
Result:
bitmapHasAny
Checks whether two bitmaps intersect.
If bitmap2 contains exactly one element, consider using bitmapContains instead as it works more efficiently.
Syntax
Arguments
bitmap1– Bitmap object 1.bitmap2– Bitmap object 2.
Return values
1, ifbitmap1andbitmap2have at least one shared element.0, otherwise.
Example
Result:
bitmapHasAll
Returns 1 if the first bitmap contains all elements of the second bitmap, otherwise 0. If the second bitmap is empty, returns 1.
Also see hasAll(array, array).
Syntax
Arguments
bitmap1– Bitmap object 1.bitmap2– Bitmap object 2.
Example
Result:
bitmapCardinality
Returns the cardinality of a bitmap.
Syntax
Arguments
bitmap– Bitmap object.
Example
Result:
bitmapMin
Computes the smallest bit set in a bitmap, or UINT32_MAX if the bitmap is empty.
Syntax
Arguments
bitmap– Bitmap object.
Example
Result:
bitmapMax
Computes the greatest bit set in a bitmap, or 0 if the bitmap is empty.
Syntax
Arguments
bitmap– Bitmap object.
Example
Result:
bitmapTransform
Replaces at most N bits in a bitmap. The old and new value of the i-th replaced bit is given by from_array[i] and to_array[i].
The result depends on the array ordering if from_array and to_array.
Syntax
Arguments
bitmap– Bitmap object.from_array– UInt32 array. For idx in range [0, from_array.size()), if bitmap contains from_array[idx], then replace it with to_array[idx].to_array– UInt32 array with the same size asfrom_array.
Example
Result:
bitmapAnd
Computes the logical conjunction of two bitmaps.
Syntax
Arguments
bitmap– Bitmap object.
Example
Result:
bitmapOr
Computes the logical disjunction of two bitmaps.
Syntax
Arguments
bitmap– Bitmap object.
Example
Result:
bitmapXor
Xor-s two bitmaps.
Syntax
Arguments
bitmap– Bitmap object.
Example
Result:
bitmapAndnot
Computes the logical conjunction of two bitmaps and negates the result.
Syntax
Arguments
bitmap– Bitmap object.
Example
Result:
bitmapAndCardinality
Returns the cardinality of the logical conjunction of two bitmaps.
Syntax
Arguments
bitmap– Bitmap object.
Example
Result:
bitmapOrCardinality
Returns the cardinality of the logical disjunction of two bitmaps.
Arguments
bitmap– Bitmap object.
Example
Result:
bitmapXorCardinality
Returns the cardinality of the XOR of two bitmaps.
Arguments
bitmap– Bitmap object.
Example
Result:
bitmapAndnotCardinality
Returns the cardinality of the AND-NOT operation of two bitmaps.
Arguments
bitmap– Bitmap object.
Example
Result: