forked from ChenHuajun/pg_roaringbitmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
roaring.c
11640 lines (10725 loc) · 468 KB
/
roaring.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* auto-generated on Sat Jun 27 12:40:38 2020. Do not edit! */
#include "roaring.h"
/* used for http://dmalloc.com/ Dmalloc - Debug Malloc Library */
#ifdef DMALLOC
#include "dmalloc.h"
#endif
/* begin file src/array_util.c */
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
extern inline int32_t binarySearch(const uint16_t *array, int32_t lenarray,
uint16_t ikey);
#ifdef USESSE4
// used by intersect_vector16
ALIGNED(0x1000)
static const uint8_t shuffle_mask16[] = {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0, 1, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 2, 3, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0, 1, 2, 3, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 4, 5, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0, 1, 4, 5,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
2, 3, 4, 5, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0, 1, 2, 3, 4, 5, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 6, 7, 0xFF, 0xFF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10, 11,
12, 13, 14, 15, 0xFF, 0xFF, 0xFF, 0xFF, 0, 1, 2, 3,
6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0xFF, 0xFF,
4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
0xFF, 0xFF, 0xFF, 0xFF, 0, 1, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 0xFF, 0xFF, 2, 3, 4, 5,
6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0xFF, 0xFF,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15};
/**
* From Schlegel et al., Fast Sorted-Set Intersection using SIMD Instructions
* Optimized by D. Lemire on May 3rd 2013
*/
int32_t intersect_vector16(const uint16_t *__restrict__ A, size_t s_a,
const uint16_t *__restrict__ B, size_t s_b,
uint16_t *C) {
size_t count = 0;
size_t i_a = 0, i_b = 0;
const int vectorlength = sizeof(__m128i) / sizeof(uint16_t);
const size_t st_a = (s_a / vectorlength) * vectorlength;
const size_t st_b = (s_b / vectorlength) * vectorlength;
__m128i v_a, v_b;
if ((i_a < st_a) && (i_b < st_b)) {
v_a = _mm_lddqu_si128((__m128i *)&A[i_a]);
v_b = _mm_lddqu_si128((__m128i *)&B[i_b]);
while ((A[i_a] == 0) || (B[i_b] == 0)) {
const __m128i res_v = _mm_cmpestrm(
v_b, vectorlength, v_a, vectorlength,
_SIDD_UWORD_OPS | _SIDD_CMP_EQUAL_ANY | _SIDD_BIT_MASK);
const int r = _mm_extract_epi32(res_v, 0);
__m128i sm16 = _mm_load_si128((const __m128i *)shuffle_mask16 + r);
__m128i p = _mm_shuffle_epi8(v_a, sm16);
_mm_storeu_si128((__m128i *)&C[count], p); // can overflow
count += _mm_popcnt_u32(r);
const uint16_t a_max = A[i_a + vectorlength - 1];
const uint16_t b_max = B[i_b + vectorlength - 1];
if (a_max <= b_max) {
i_a += vectorlength;
if (i_a == st_a) break;
v_a = _mm_lddqu_si128((__m128i *)&A[i_a]);
}
if (b_max <= a_max) {
i_b += vectorlength;
if (i_b == st_b) break;
v_b = _mm_lddqu_si128((__m128i *)&B[i_b]);
}
}
if ((i_a < st_a) && (i_b < st_b))
while (true) {
const __m128i res_v = _mm_cmpistrm(
v_b, v_a,
_SIDD_UWORD_OPS | _SIDD_CMP_EQUAL_ANY | _SIDD_BIT_MASK);
const int r = _mm_extract_epi32(res_v, 0);
__m128i sm16 =
_mm_load_si128((const __m128i *)shuffle_mask16 + r);
__m128i p = _mm_shuffle_epi8(v_a, sm16);
_mm_storeu_si128((__m128i *)&C[count], p); // can overflow
count += _mm_popcnt_u32(r);
const uint16_t a_max = A[i_a + vectorlength - 1];
const uint16_t b_max = B[i_b + vectorlength - 1];
if (a_max <= b_max) {
i_a += vectorlength;
if (i_a == st_a) break;
v_a = _mm_lddqu_si128((__m128i *)&A[i_a]);
}
if (b_max <= a_max) {
i_b += vectorlength;
if (i_b == st_b) break;
v_b = _mm_lddqu_si128((__m128i *)&B[i_b]);
}
}
}
// intersect the tail using scalar intersection
while (i_a < s_a && i_b < s_b) {
uint16_t a = A[i_a];
uint16_t b = B[i_b];
if (a < b) {
i_a++;
} else if (b < a) {
i_b++;
} else {
C[count] = a; //==b;
count++;
i_a++;
i_b++;
}
}
return (int32_t)count;
}
int32_t intersect_vector16_cardinality(const uint16_t *__restrict__ A,
size_t s_a,
const uint16_t *__restrict__ B,
size_t s_b) {
size_t count = 0;
size_t i_a = 0, i_b = 0;
const int vectorlength = sizeof(__m128i) / sizeof(uint16_t);
const size_t st_a = (s_a / vectorlength) * vectorlength;
const size_t st_b = (s_b / vectorlength) * vectorlength;
__m128i v_a, v_b;
if ((i_a < st_a) && (i_b < st_b)) {
v_a = _mm_lddqu_si128((__m128i *)&A[i_a]);
v_b = _mm_lddqu_si128((__m128i *)&B[i_b]);
while ((A[i_a] == 0) || (B[i_b] == 0)) {
const __m128i res_v = _mm_cmpestrm(
v_b, vectorlength, v_a, vectorlength,
_SIDD_UWORD_OPS | _SIDD_CMP_EQUAL_ANY | _SIDD_BIT_MASK);
const int r = _mm_extract_epi32(res_v, 0);
count += _mm_popcnt_u32(r);
const uint16_t a_max = A[i_a + vectorlength - 1];
const uint16_t b_max = B[i_b + vectorlength - 1];
if (a_max <= b_max) {
i_a += vectorlength;
if (i_a == st_a) break;
v_a = _mm_lddqu_si128((__m128i *)&A[i_a]);
}
if (b_max <= a_max) {
i_b += vectorlength;
if (i_b == st_b) break;
v_b = _mm_lddqu_si128((__m128i *)&B[i_b]);
}
}
if ((i_a < st_a) && (i_b < st_b))
while (true) {
const __m128i res_v = _mm_cmpistrm(
v_b, v_a,
_SIDD_UWORD_OPS | _SIDD_CMP_EQUAL_ANY | _SIDD_BIT_MASK);
const int r = _mm_extract_epi32(res_v, 0);
count += _mm_popcnt_u32(r);
const uint16_t a_max = A[i_a + vectorlength - 1];
const uint16_t b_max = B[i_b + vectorlength - 1];
if (a_max <= b_max) {
i_a += vectorlength;
if (i_a == st_a) break;
v_a = _mm_lddqu_si128((__m128i *)&A[i_a]);
}
if (b_max <= a_max) {
i_b += vectorlength;
if (i_b == st_b) break;
v_b = _mm_lddqu_si128((__m128i *)&B[i_b]);
}
}
}
// intersect the tail using scalar intersection
while (i_a < s_a && i_b < s_b) {
uint16_t a = A[i_a];
uint16_t b = B[i_b];
if (a < b) {
i_a++;
} else if (b < a) {
i_b++;
} else {
count++;
i_a++;
i_b++;
}
}
return (int32_t)count;
}
/////////
// Warning:
// This function may not be safe if A == C or B == C.
/////////
int32_t difference_vector16(const uint16_t *__restrict__ A, size_t s_a,
const uint16_t *__restrict__ B, size_t s_b,
uint16_t *C) {
// we handle the degenerate case
if (s_a == 0) return 0;
if (s_b == 0) {
if (A != C) memcpy(C, A, sizeof(uint16_t) * s_a);
return (int32_t)s_a;
}
// handle the leading zeroes, it is messy but it allows us to use the fast
// _mm_cmpistrm instrinsic safely
int32_t count = 0;
if ((A[0] == 0) || (B[0] == 0)) {
if ((A[0] == 0) && (B[0] == 0)) {
A++;
s_a--;
B++;
s_b--;
} else if (A[0] == 0) {
C[count++] = 0;
A++;
s_a--;
} else {
B++;
s_b--;
}
}
// at this point, we have two non-empty arrays, made of non-zero
// increasing values.
size_t i_a = 0, i_b = 0;
const size_t vectorlength = sizeof(__m128i) / sizeof(uint16_t);
const size_t st_a = (s_a / vectorlength) * vectorlength;
const size_t st_b = (s_b / vectorlength) * vectorlength;
if ((i_a < st_a) && (i_b < st_b)) { // this is the vectorized code path
__m128i v_a, v_b; //, v_bmax;
// we load a vector from A and a vector from B
v_a = _mm_lddqu_si128((__m128i *)&A[i_a]);
v_b = _mm_lddqu_si128((__m128i *)&B[i_b]);
// we have a runningmask which indicates which values from A have been
// spotted in B, these don't get written out.
__m128i runningmask_a_found_in_b = _mm_setzero_si128();
/****
* start of the main vectorized loop
*****/
while (true) {
// afoundinb will contain a mask indicate for each entry in A
// whether it is seen
// in B
const __m128i a_found_in_b =
_mm_cmpistrm(v_b, v_a, _SIDD_UWORD_OPS | _SIDD_CMP_EQUAL_ANY |
_SIDD_BIT_MASK);
runningmask_a_found_in_b =
_mm_or_si128(runningmask_a_found_in_b, a_found_in_b);
// we always compare the last values of A and B
const uint16_t a_max = A[i_a + vectorlength - 1];
const uint16_t b_max = B[i_b + vectorlength - 1];
if (a_max <= b_max) {
// Ok. In this code path, we are ready to write our v_a
// because there is no need to read more from B, they will
// all be large values.
const int bitmask_belongs_to_difference =
_mm_extract_epi32(runningmask_a_found_in_b, 0) ^ 0xFF;
/*** next few lines are probably expensive *****/
__m128i sm16 = _mm_load_si128((const __m128i *)shuffle_mask16 +
bitmask_belongs_to_difference);
__m128i p = _mm_shuffle_epi8(v_a, sm16);
_mm_storeu_si128((__m128i *)&C[count], p); // can overflow
count += _mm_popcnt_u32(bitmask_belongs_to_difference);
// we advance a
i_a += vectorlength;
if (i_a == st_a) // no more
break;
runningmask_a_found_in_b = _mm_setzero_si128();
v_a = _mm_lddqu_si128((__m128i *)&A[i_a]);
}
if (b_max <= a_max) {
// in this code path, the current v_b has become useless
i_b += vectorlength;
if (i_b == st_b) break;
v_b = _mm_lddqu_si128((__m128i *)&B[i_b]);
}
}
// at this point, either we have i_a == st_a, which is the end of the
// vectorized processing,
// or we have i_b == st_b, and we are not done processing the vector...
// so we need to finish it off.
if (i_a < st_a) { // we have unfinished business...
uint16_t buffer[8]; // buffer to do a masked load
memset(buffer, 0, 8 * sizeof(uint16_t));
memcpy(buffer, B + i_b, (s_b - i_b) * sizeof(uint16_t));
v_b = _mm_lddqu_si128((__m128i *)buffer);
const __m128i a_found_in_b =
_mm_cmpistrm(v_b, v_a, _SIDD_UWORD_OPS | _SIDD_CMP_EQUAL_ANY |
_SIDD_BIT_MASK);
runningmask_a_found_in_b =
_mm_or_si128(runningmask_a_found_in_b, a_found_in_b);
const int bitmask_belongs_to_difference =
_mm_extract_epi32(runningmask_a_found_in_b, 0) ^ 0xFF;
__m128i sm16 = _mm_load_si128((const __m128i *)shuffle_mask16 +
bitmask_belongs_to_difference);
__m128i p = _mm_shuffle_epi8(v_a, sm16);
_mm_storeu_si128((__m128i *)&C[count], p); // can overflow
count += _mm_popcnt_u32(bitmask_belongs_to_difference);
i_a += vectorlength;
}
// at this point we should have i_a == st_a and i_b == st_b
}
// do the tail using scalar code
while (i_a < s_a && i_b < s_b) {
uint16_t a = A[i_a];
uint16_t b = B[i_b];
if (b < a) {
i_b++;
} else if (a < b) {
C[count] = a;
count++;
i_a++;
} else { //==
i_a++;
i_b++;
}
}
if (i_a < s_a) {
if(C == A) {
assert((size_t)count <= i_a);
if((size_t)count < i_a) {
memmove(C + count, A + i_a, sizeof(uint16_t) * (s_a - i_a));
}
} else {
for(size_t i = 0; i < (s_a - i_a); i++) {
C[count + i] = A[i + i_a];
}
}
count += (int32_t)(s_a - i_a);
}
return count;
}
#endif // USESSE4
#ifdef USE_OLD_SKEW_INTERSECT
// TODO: given enough experience with the new skew intersect, drop the old one from the code base.
/* Computes the intersection between one small and one large set of uint16_t.
* Stores the result into buffer and return the number of elements. */
int32_t intersect_skewed_uint16(const uint16_t *small, size_t size_s,
const uint16_t *large, size_t size_l,
uint16_t *buffer) {
size_t pos = 0, idx_l = 0, idx_s = 0;
if (0 == size_s) {
return 0;
}
uint16_t val_l = large[idx_l], val_s = small[idx_s];
while (true) {
if (val_l < val_s) {
idx_l = advanceUntil(large, (int32_t)idx_l, (int32_t)size_l, val_s);
if (idx_l == size_l) break;
val_l = large[idx_l];
} else if (val_s < val_l) {
idx_s++;
if (idx_s == size_s) break;
val_s = small[idx_s];
} else {
buffer[pos++] = val_s;
idx_s++;
if (idx_s == size_s) break;
val_s = small[idx_s];
idx_l = advanceUntil(large, (int32_t)idx_l, (int32_t)size_l, val_s);
if (idx_l == size_l) break;
val_l = large[idx_l];
}
}
return (int32_t)pos;
}
#else // USE_OLD_SKEW_INTERSECT
/**
* Branchless binary search going after 4 values at once.
* Assumes that array is sorted.
* You have that array[*index1] >= target1, array[*index12] >= target2, ...
* except when *index1 = n, in which case you know that all values in array are
* smaller than target1, and so forth.
* It has logarithmic complexity.
*/
static void binarySearch4(const uint16_t *array, int32_t n, uint16_t target1,
uint16_t target2, uint16_t target3, uint16_t target4,
int32_t *index1, int32_t *index2, int32_t *index3,
int32_t *index4) {
const uint16_t *base1 = array;
const uint16_t *base2 = array;
const uint16_t *base3 = array;
const uint16_t *base4 = array;
if (n == 0)
return;
while (n > 1) {
int32_t half = n >> 1;
base1 = (base1[half] < target1) ? &base1[half] : base1;
base2 = (base2[half] < target2) ? &base2[half] : base2;
base3 = (base3[half] < target3) ? &base3[half] : base3;
base4 = (base4[half] < target4) ? &base4[half] : base4;
n -= half;
}
*index1 = (int32_t)((*base1 < target1) + base1 - array);
*index2 = (int32_t)((*base2 < target2) + base2 - array);
*index3 = (int32_t)((*base3 < target3) + base3 - array);
*index4 = (int32_t)((*base4 < target4) + base4 - array);
}
/**
* Branchless binary search going after 2 values at once.
* Assumes that array is sorted.
* You have that array[*index1] >= target1, array[*index12] >= target2.
* except when *index1 = n, in which case you know that all values in array are
* smaller than target1, and so forth.
* It has logarithmic complexity.
*/
static void binarySearch2(const uint16_t *array, int32_t n, uint16_t target1,
uint16_t target2, int32_t *index1, int32_t *index2) {
const uint16_t *base1 = array;
const uint16_t *base2 = array;
if (n == 0)
return;
while (n > 1) {
int32_t half = n >> 1;
base1 = (base1[half] < target1) ? &base1[half] : base1;
base2 = (base2[half] < target2) ? &base2[half] : base2;
n -= half;
}
*index1 = (int32_t)((*base1 < target1) + base1 - array);
*index2 = (int32_t)((*base2 < target2) + base2 - array);
}
/* Computes the intersection between one small and one large set of uint16_t.
* Stores the result into buffer and return the number of elements.
* Processes the small set in blocks of 4 values calling binarySearch4
* and binarySearch2. This approach can be slightly superior to a conventional
* galloping search in some instances.
*/
int32_t intersect_skewed_uint16(const uint16_t *small, size_t size_s,
const uint16_t *large, size_t size_l,
uint16_t *buffer) {
size_t pos = 0, idx_l = 0, idx_s = 0;
if (0 == size_s) {
return 0;
}
int32_t index1 = 0, index2 = 0, index3 = 0, index4 = 0;
while ((idx_s + 4 <= size_s) && (idx_l < size_l)) {
uint16_t target1 = small[idx_s];
uint16_t target2 = small[idx_s + 1];
uint16_t target3 = small[idx_s + 2];
uint16_t target4 = small[idx_s + 3];
binarySearch4(large + idx_l, (int32_t)(size_l - idx_l), target1, target2, target3,
target4, &index1, &index2, &index3, &index4);
if ((index1 + idx_l < size_l) && (large[idx_l + index1] == target1)) {
buffer[pos++] = target1;
}
if ((index2 + idx_l < size_l) && (large[idx_l + index2] == target2)) {
buffer[pos++] = target2;
}
if ((index3 + idx_l < size_l) && (large[idx_l + index3] == target3)) {
buffer[pos++] = target3;
}
if ((index4 + idx_l < size_l) && (large[idx_l + index4] == target4)) {
buffer[pos++] = target4;
}
idx_s += 4;
idx_l += index4;
}
if ((idx_s + 2 <= size_s) && (idx_l < size_l)) {
uint16_t target1 = small[idx_s];
uint16_t target2 = small[idx_s + 1];
binarySearch2(large + idx_l, (int32_t)(size_l - idx_l), target1, target2, &index1,
&index2);
if ((index1 + idx_l < size_l) && (large[idx_l + index1] == target1)) {
buffer[pos++] = target1;
}
if ((index2 + idx_l < size_l) && (large[idx_l + index2] == target2)) {
buffer[pos++] = target2;
}
idx_s += 2;
idx_l += index2;
}
if ((idx_s < size_s) && (idx_l < size_l)) {
uint16_t val_s = small[idx_s];
int32_t index = binarySearch(large + idx_l, (int32_t)(size_l - idx_l), val_s);
if (index >= 0)
buffer[pos++] = val_s;
}
return (int32_t)pos;
}
#endif //USE_OLD_SKEW_INTERSECT
// TODO: this could be accelerated, possibly, by using binarySearch4 as above.
int32_t intersect_skewed_uint16_cardinality(const uint16_t *small,
size_t size_s,
const uint16_t *large,
size_t size_l) {
size_t pos = 0, idx_l = 0, idx_s = 0;
if (0 == size_s) {
return 0;
}
uint16_t val_l = large[idx_l], val_s = small[idx_s];
while (true) {
if (val_l < val_s) {
idx_l = advanceUntil(large, (int32_t)idx_l, (int32_t)size_l, val_s);
if (idx_l == size_l) break;
val_l = large[idx_l];
} else if (val_s < val_l) {
idx_s++;
if (idx_s == size_s) break;
val_s = small[idx_s];
} else {
pos++;
idx_s++;
if (idx_s == size_s) break;
val_s = small[idx_s];
idx_l = advanceUntil(large, (int32_t)idx_l, (int32_t)size_l, val_s);
if (idx_l == size_l) break;
val_l = large[idx_l];
}
}
return (int32_t)pos;
}
bool intersect_skewed_uint16_nonempty(const uint16_t *small, size_t size_s,
const uint16_t *large, size_t size_l) {
size_t idx_l = 0, idx_s = 0;
if (0 == size_s) {
return false;
}
uint16_t val_l = large[idx_l], val_s = small[idx_s];
while (true) {
if (val_l < val_s) {
idx_l = advanceUntil(large, (int32_t)idx_l, (int32_t)size_l, val_s);
if (idx_l == size_l) break;
val_l = large[idx_l];
} else if (val_s < val_l) {
idx_s++;
if (idx_s == size_s) break;
val_s = small[idx_s];
} else {
return true;
}
}
return false;
}
/**
* Generic intersection function.
*/
int32_t intersect_uint16(const uint16_t *A, const size_t lenA,
const uint16_t *B, const size_t lenB, uint16_t *out) {
const uint16_t *initout = out;
if (lenA == 0 || lenB == 0) return 0;
const uint16_t *endA = A + lenA;
const uint16_t *endB = B + lenB;
while (1) {
while (*A < *B) {
SKIP_FIRST_COMPARE:
if (++A == endA) return (int32_t)(out - initout);
}
while (*A > *B) {
if (++B == endB) return (int32_t)(out - initout);
}
if (*A == *B) {
*out++ = *A;
if (++A == endA || ++B == endB) return (int32_t)(out - initout);
} else {
goto SKIP_FIRST_COMPARE;
}
}
return (int32_t)(out - initout); // NOTREACHED
}
int32_t intersect_uint16_cardinality(const uint16_t *A, const size_t lenA,
const uint16_t *B, const size_t lenB) {
int32_t answer = 0;
if (lenA == 0 || lenB == 0) return 0;
const uint16_t *endA = A + lenA;
const uint16_t *endB = B + lenB;
while (1) {
while (*A < *B) {
SKIP_FIRST_COMPARE:
if (++A == endA) return answer;
}
while (*A > *B) {
if (++B == endB) return answer;
}
if (*A == *B) {
++answer;
if (++A == endA || ++B == endB) return answer;
} else {
goto SKIP_FIRST_COMPARE;
}
}
return answer; // NOTREACHED
}
bool intersect_uint16_nonempty(const uint16_t *A, const size_t lenA,
const uint16_t *B, const size_t lenB) {
if (lenA == 0 || lenB == 0) return 0;
const uint16_t *endA = A + lenA;
const uint16_t *endB = B + lenB;
while (1) {
while (*A < *B) {
SKIP_FIRST_COMPARE:
if (++A == endA) return false;
}
while (*A > *B) {
if (++B == endB) return false;
}
if (*A == *B) {
return true;
} else {
goto SKIP_FIRST_COMPARE;
}
}
return false; // NOTREACHED
}
/**
* Generic intersection function.
*/
size_t intersection_uint32(const uint32_t *A, const size_t lenA,
const uint32_t *B, const size_t lenB,
uint32_t *out) {
const uint32_t *initout = out;
if (lenA == 0 || lenB == 0) return 0;
const uint32_t *endA = A + lenA;
const uint32_t *endB = B + lenB;
while (1) {
while (*A < *B) {
SKIP_FIRST_COMPARE:
if (++A == endA) return (out - initout);
}
while (*A > *B) {
if (++B == endB) return (out - initout);
}
if (*A == *B) {
*out++ = *A;
if (++A == endA || ++B == endB) return (out - initout);
} else {
goto SKIP_FIRST_COMPARE;
}
}
return (out - initout); // NOTREACHED
}
size_t intersection_uint32_card(const uint32_t *A, const size_t lenA,
const uint32_t *B, const size_t lenB) {
if (lenA == 0 || lenB == 0) return 0;
size_t card = 0;