]>
git.zerfleddert.de Git - proxmark3-svn/blob - common/bucketsort.c
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
)
16 // init buckets to be empty
17 for (uint32_t i
= 0; i
< 2; i
++) {
18 for (uint32_t j
= 0x00; j
<= 0xff; j
++) {
19 bucket
[i
][j
].bp
= bucket
[i
][j
].head
;
23 // sort the lists into the buckets based on the MSB (contribution bits)
24 for (uint32_t i
= 0; i
< 2; i
++) {
25 for (p1
= start
[i
]; p1
<= stop
[i
]; p1
++) {
26 uint32_t bucket_index
= (*p1
& 0xff000000) >> 24;
27 *(bucket
[i
][bucket_index
].bp
++) = *p1
;
31 // write back intersecting buckets as sorted list.
32 // fill in bucket_info with head and tail of the bucket contents in the list and number of non-empty buckets.
33 uint32_t nonempty_bucket
;
34 for (uint32_t i
= 0; i
< 2; i
++) {
37 for (uint32_t j
= 0x00; j
<= 0xff; j
++) {
38 if (bucket
[0][j
].bp
!= bucket
[0][j
].head
&& bucket
[1][j
].bp
!= bucket
[1][j
].head
) { // non-empty intersecting buckets only
39 bucket_info
->bucket_info
[i
][nonempty_bucket
].head
= p1
;
40 for (p2
= bucket
[i
][j
].head
; p2
< bucket
[i
][j
].bp
; *p1
++ = *p2
++);
41 bucket_info
->bucket_info
[i
][nonempty_bucket
].tail
= p1
- 1;
45 bucket_info
->numbuckets
= nonempty_bucket
;