I have used some 'hack' to implement this sorting.
- Make the two attributes to sort to be
uint32_t
types. - Add another attribute
uint64_t
for_sort
to my struct - Shift the upper 32 bits of
for_sort
to beattr1
- The lower 32 bits of
for_sort
to beattr2
- Sort the array by
for_sort
, then the items are first sorted byattr1
, then byattr2
.
I have implemented and verified that it is working.
Disadvantages:
- Extra memory to add
for_sort
- Extra processing
- If the sorting attributes are in other types, need to change accordingly.