1 #include "bucketsort.h"
3 extern void bucket_sort_intersect(uint32_t *const estart
, uint32_t *const estop
,
4 uint32_t *const ostart
, uint32_t *const ostop
,
5 bucket_info_t
*bucket_info
, bucket_array_t bucket
) {
15 // init buckets to be empty
16 for (uint32_t i
= 0; i
< 2; i
++) {
17 for (uint32_t j
= 0x00; j
<= 0xff; j
++) {
18 bucket
[i
][j
].bp
= bucket
[i
][j
].head
;
22 // sort the lists into the buckets based on the MSB (contribution bits)
23 for (uint32_t i
= 0; i
< 2; i
++) {
24 for (p1
= start
[i
]; p1
<= stop
[i
]; p1
++) {
25 uint32_t bucket_index
= (*p1
& 0xff000000) >> 24;
26 *(bucket
[i
][bucket_index
].bp
++) = *p1
;
30 // write back intersecting buckets as sorted list.
31 // fill in bucket_info with head and tail of the bucket contents in the list and number of non-empty buckets.
32 for (uint32_t i
= 0; i
< 2; i
++) {
34 uint32_t nonempty_bucket
= 0;
35 for (uint32_t j
= 0x00; j
<= 0xff; j
++) {
36 if (bucket
[0][j
].bp
!= bucket
[0][j
].head
&& bucket
[1][j
].bp
!= bucket
[1][j
].head
) { // non-empty intersecting buckets only
37 bucket_info
->bucket_info
[i
][nonempty_bucket
].head
= p1
;
38 for (p2
= bucket
[i
][j
].head
; p2
< bucket
[i
][j
].bp
; *p1
++ = *p2
++);
39 bucket_info
->bucket_info
[i
][nonempty_bucket
].tail
= p1
- 1;
43 bucket_info
->numbuckets
= nonempty_bucket
;