creates a new chain node with the given parameters, from the memory in the lists */
| 888 | |
| 889 | /*creates a new chain node with the given parameters, from the memory in the lists */ |
| 890 | static BPMNode* bpmnode_create(BPMLists* lists, int weight, unsigned index, BPMNode* tail) { |
| 891 | unsigned i; |
| 892 | BPMNode* result; |
| 893 | |
| 894 | /*memory full, so garbage collect*/ |
| 895 | if(lists->nextfree >= lists->numfree) { |
| 896 | /*mark only those that are in use*/ |
| 897 | for(i = 0; i != lists->memsize; ++i) lists->memory[i].in_use = 0; |
| 898 | for(i = 0; i != lists->listsize; ++i) { |
| 899 | BPMNode* node; |
| 900 | for(node = lists->chains0[i]; node != 0; node = node->tail) node->in_use = 1; |
| 901 | for(node = lists->chains1[i]; node != 0; node = node->tail) node->in_use = 1; |
| 902 | } |
| 903 | /*collect those that are free*/ |
| 904 | lists->numfree = 0; |
| 905 | for(i = 0; i != lists->memsize; ++i) { |
| 906 | if(!lists->memory[i].in_use) lists->freelist[lists->numfree++] = &lists->memory[i]; |
| 907 | } |
| 908 | lists->nextfree = 0; |
| 909 | } |
| 910 | |
| 911 | result = lists->freelist[lists->nextfree++]; |
| 912 | result->weight = weight; |
| 913 | result->index = index; |
| 914 | result->tail = tail; |
| 915 | return result; |
| 916 | } |
| 917 | |
| 918 | /*sort the leaves with stable mergesort*/ |
| 919 | static void bpmnode_sort(BPMNode* leaves, size_t num) { |
no outgoing calls
no test coverage detected