MCPcopy Create free account
hub / github.com/HiLab-git/SimpleCRF / bpmnode_sort

Function bpmnode_sort

dependency/densecrf/examples/lodepng.cpp:731–755  ·  view source on GitHub ↗

sort the leaves with stable mergesort*/

Source from the content-addressed store, hash-verified

729
730/*sort the leaves with stable mergesort*/
731static 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.*/
758static void boundaryPM(BPMLists* lists, BPMNode* leaves, size_t numpresent, int c, int num)

Callers 1

Calls 2

lodepng_mallocFunction · 0.85
lodepng_freeFunction · 0.85

Tested by

no test coverage detected