Skip to content

Commit 7bd53ce

Browse files
committed
Adding more comments.
1 parent eac38a0 commit 7bd53ce

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/containers/mixed_union.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,17 @@ bool array_array_container_lazy_union(
242242
container_t **dst
243243
){
244244
int totalCardinality = src_1->cardinality + src_2->cardinality;
245+
//
246+
// We assume that operations involving bitset containers will be faster than
247+
// operations involving solely array containers, except maybe when array containers
248+
// are small. Indeed, for example, it is cheap to compute the union between an array and
249+
// a bitset container, generally more so than between a large array and another array.
250+
// So it is advantageous to favour bitset containers during the computation.
251+
// Of course, if we convert array containers eagerly to bitset containers, we may later
252+
// need to revert the bitset containers to array containerr to satisfy the Roaring format requirements,
253+
// but such one-time conversions at the end may not be overly expensive. We arrived to this design
254+
// based on extensive benchmarking.
255+
//
245256
if (totalCardinality <= ARRAY_LAZY_LOWERBOUND) {
246257
*dst = array_container_create_given_capacity(totalCardinality);
247258
if (*dst != NULL) {
@@ -269,6 +280,17 @@ bool array_array_container_lazy_inplace_union(
269280
){
270281
int totalCardinality = src_1->cardinality + src_2->cardinality;
271282
*dst = NULL;
283+
//
284+
// We assume that operations involving bitset containers will be faster than
285+
// operations involving solely array containers, except maybe when array containers
286+
// are small. Indeed, for example, it is cheap to compute the union between an array and
287+
// a bitset container, generally more so than between a large array and another array.
288+
// So it is advantageous to favour bitset containers during the computation.
289+
// Of course, if we convert array containers eagerly to bitset containers, we may later
290+
// need to revert the bitset containers to array containerr to satisfy the Roaring format requirements,
291+
// but such one-time conversions at the end may not be overly expensive. We arrived to this design
292+
// based on extensive benchmarking.
293+
//
272294
if (totalCardinality <= ARRAY_LAZY_LOWERBOUND) {
273295
if(src_1->capacity < totalCardinality) {
274296
*dst = array_container_create_given_capacity(2 * totalCardinality); // be purposefully generous

src/containers/mixed_xor.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,19 @@ bool array_array_container_lazy_xor(
230230
container_t **dst
231231
){
232232
int totalCardinality = src_1->cardinality + src_2->cardinality;
233-
// upper bound, but probably poor estimate for xor
233+
//
234+
// We assume that operations involving bitset containers will be faster than
235+
// operations involving solely array containers, except maybe when array containers
236+
// are small. Indeed, for example, it is cheap to compute the exclusive union between an array and
237+
// a bitset container, generally more so than between a large array and another array.
238+
// So it is advantageous to favour bitset containers during the computation.
239+
// Of course, if we convert array containers eagerly to bitset containers, we may later
240+
// need to revert the bitset containers to array containerr to satisfy the Roaring format requirements,
241+
// but such one-time conversions at the end may not be overly expensive. We arrived to this design
242+
// based on extensive benchmarking on unions.
243+
// For XOR/exclusive union, we simply followed the heuristic used by the unions (see mixed_union.c).
244+
// Further tuning is possible.
245+
//
234246
if (totalCardinality <= ARRAY_LAZY_LOWERBOUND) {
235247
*dst = array_container_create_given_capacity(totalCardinality);
236248
if (*dst != NULL)

0 commit comments

Comments
 (0)