sort the leaves with stable mergesort*/
| 729 | |
| 730 | /*sort the leaves with stable mergesort*/ |
| 731 | static void bpmnode_sort(BPMNode* leaves, size_t num) |
| 732 | { |
| 733 | BPMNode* mem = (BPMNode*)lodepng_malloc(sizeof(*leaves) * num); |
| 734 | size_t width, counter = 0; |
| 735 | for(width = 1; width < num; width *= 2) |
| 736 | { |
| 737 | BPMNode* a = (counter & 1) ? mem : leaves; |
| 738 | BPMNode* b = (counter & 1) ? leaves : mem; |
| 739 | size_t p; |
| 740 | for(p = 0; p < num; p += 2 * width) |
| 741 | { |
| 742 | size_t q = (p + width > num) ? num : (p + width); |
| 743 | size_t r = (p + 2 * width > num) ? num : (p + 2 * width); |
| 744 | size_t i = p, j = q, k; |
| 745 | for(k = p; k < r; k++) |
| 746 | { |
| 747 | if(i < q && (j >= r || a[i].weight <= a[j].weight)) b[k] = a[i++]; |
| 748 | else b[k] = a[j++]; |
| 749 | } |
| 750 | } |
| 751 | counter++; |
| 752 | } |
| 753 | if(counter & 1) memcpy(leaves, mem, sizeof(*leaves) * num); |
| 754 | lodepng_free(mem); |
| 755 | } |
| 756 | |
| 757 | /*Boundary Package Merge step, numpresent is the amount of leaves, and c is the current chain.*/ |
| 758 | static void boundaryPM(BPMLists* lists, BPMNode* leaves, size_t numpresent, int c, int num) |
no test coverage detected