sort the leaves with stable mergesort*/
| 917 | |
| 918 | /*sort the leaves with stable mergesort*/ |
| 919 | static void bpmnode_sort(BPMNode* leaves, size_t num) { |
| 920 | BPMNode* mem = (BPMNode*)lodepng_malloc(sizeof(*leaves) * num); |
| 921 | size_t width, counter = 0; |
| 922 | for(width = 1; width < num; width *= 2) { |
| 923 | BPMNode* a = (counter & 1) ? mem : leaves; |
| 924 | BPMNode* b = (counter & 1) ? leaves : mem; |
| 925 | size_t p; |
| 926 | for(p = 0; p < num; p += 2 * width) { |
| 927 | size_t q = (p + width > num) ? num : (p + width); |
| 928 | size_t r = (p + 2 * width > num) ? num : (p + 2 * width); |
| 929 | size_t i = p, j = q, k; |
| 930 | for(k = p; k < r; k++) { |
| 931 | if(i < q && (j >= r || a[i].weight <= a[j].weight)) b[k] = a[i++]; |
| 932 | else b[k] = a[j++]; |
| 933 | } |
| 934 | } |
| 935 | counter++; |
| 936 | } |
| 937 | if(counter & 1) lodepng_memcpy(leaves, mem, sizeof(*leaves) * num); |
| 938 | lodepng_free(mem); |
| 939 | } |
| 940 | |
| 941 | /*Boundary Package Merge step, numpresent is the amount of leaves, and c is the current chain.*/ |
| 942 | static void boundaryPM(BPMLists* lists, BPMNode* leaves, size_t numpresent, int c, int num) { |
no test coverage detected