creates a new chain node with the given parameters, from the memory in the lists */
| 863 | |
| 864 | /*creates a new chain node with the given parameters, from the memory in the lists */ |
| 865 | static BPMNode* bpmnode_create(BPMLists* lists, int weight, unsigned index, BPMNode* tail) { |
| 866 | unsigned i; |
| 867 | BPMNode* result; |
| 868 | |
| 869 | /*memory full, so garbage collect*/ |
| 870 | if(lists->nextfree >= lists->numfree) { |
| 871 | /*mark only those that are in use*/ |
| 872 | for(i = 0; i != lists->memsize; ++i) lists->memory[i].in_use = 0; |
| 873 | for(i = 0; i != lists->listsize; ++i) { |
| 874 | BPMNode* node; |
| 875 | for(node = lists->chains0[i]; node != 0; node = node->tail) node->in_use = 1; |
| 876 | for(node = lists->chains1[i]; node != 0; node = node->tail) node->in_use = 1; |
| 877 | } |
| 878 | /*collect those that are free*/ |
| 879 | lists->numfree = 0; |
| 880 | for(i = 0; i != lists->memsize; ++i) { |
| 881 | if(!lists->memory[i].in_use) lists->freelist[lists->numfree++] = &lists->memory[i]; |
| 882 | } |
| 883 | lists->nextfree = 0; |
| 884 | } |
| 885 | |
| 886 | result = lists->freelist[lists->nextfree++]; |
| 887 | result->weight = weight; |
| 888 | result->index = index; |
| 889 | result->tail = tail; |
| 890 | return result; |
| 891 | } |
| 892 | |
| 893 | /*sort the leaves with stable mergesort*/ |
| 894 | static void bpmnode_sort(BPMNode* leaves, size_t num) { |
no outgoing calls
no test coverage detected