creates a new chain node with the given parameters, from the memory in the lists */
| 696 | |
| 697 | /*creates a new chain node with the given parameters, from the memory in the lists */ |
| 698 | static BPMNode* bpmnode_create(BPMLists* lists, int weight, unsigned index, BPMNode* tail) |
| 699 | { |
| 700 | unsigned i; |
| 701 | BPMNode* result; |
| 702 | |
| 703 | /*memory full, so garbage collect*/ |
| 704 | if(lists->nextfree >= lists->numfree) |
| 705 | { |
| 706 | /*mark only those that are in use*/ |
| 707 | for(i = 0; i != lists->memsize; ++i) lists->memory[i].in_use = 0; |
| 708 | for(i = 0; i != lists->listsize; ++i) |
| 709 | { |
| 710 | BPMNode* node; |
| 711 | for(node = lists->chains0[i]; node != 0; node = node->tail) node->in_use = 1; |
| 712 | for(node = lists->chains1[i]; node != 0; node = node->tail) node->in_use = 1; |
| 713 | } |
| 714 | /*collect those that are free*/ |
| 715 | lists->numfree = 0; |
| 716 | for(i = 0; i != lists->memsize; ++i) |
| 717 | { |
| 718 | if(!lists->memory[i].in_use) lists->freelist[lists->numfree++] = &lists->memory[i]; |
| 719 | } |
| 720 | lists->nextfree = 0; |
| 721 | } |
| 722 | |
| 723 | result = lists->freelist[lists->nextfree++]; |
| 724 | result->weight = weight; |
| 725 | result->index = index; |
| 726 | result->tail = tail; |
| 727 | return result; |
| 728 | } |
| 729 | |
| 730 | /*sort the leaves with stable mergesort*/ |
| 731 | static void bpmnode_sort(BPMNode* leaves, size_t num) |
no outgoing calls
no test coverage detected