Skip to content

Commit 95809b9

Browse files
committed
Empty trees allowed
1 parent 8aa88a1 commit 95809b9

File tree

2 files changed

+27
-23
lines changed

2 files changed

+27
-23
lines changed

best.c

+16-21
Original file line numberDiff line numberDiff line change
@@ -223,30 +223,25 @@ Tree *best_core(BestConfig *bo)
223223

224224
if (!bo->is_skip_mmerge) {
225225
c_begin = clock();
226+
Tree *forest[7];
227+
forest[1] = t_nj_ds;
228+
forest[3] = t_nj_dn;
229+
forest[4] = t_nj_mm;
226230
if (bo->is_phyml) { /* tree merge */
227-
Tree *forest[7];
228-
forest[0] = t_phyml_nt; forest[1] = t_nj_ds;
229-
forest[2] = t_phyml_aa; forest[3] = t_nj_dn;
230-
forest[4] = t_nj_mm;
231-
if (bo->ctree == 0) {
232-
t_final = tr_mmerge(5, forest);
233-
} else {
234-
forest[5] = t_nj_dn_cons;
235-
forest[6] = t_nj_mm_cons;
236-
t_final = tr_mmerge(7, forest);
237-
}
231+
forest[0] = t_phyml_nt;
232+
forest[2] = t_phyml_aa;
238233
} else {
239-
Tree *forest[5];
240-
forest[0] = t_nj_mm;
241-
forest[1] = t_nj_dn; forest[2] = t_nj_ds;
242-
if (bo->ctree == 0) {
243-
t_final = tr_mmerge(3, forest);
244-
} else {
245-
forest[3] = t_nj_dn_cons;
246-
forest[4] = t_nj_mm_cons;
247-
t_final = tr_mmerge(5, forest);
248-
}
234+
forest[0] = NULL;
235+
forest[2] = NULL;
236+
}
237+
if (bo->ctree == 0) {
238+
forest[5] = NULL;
239+
forest[6] = NULL;
240+
} else {
241+
forest[5] = t_nj_dn_cons;
242+
forest[6] = t_nj_mm_cons;
249243
}
244+
t_final = tr_mmerge(7, forest);
250245
if (bo->is_debug) fprintf(stderr, "tree merge: %.2fs\n", (float)(clock() - c_begin) / CLOCKS_PER_SEC);
251246

252247
} else {

mmerge.cc

+11-2
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,11 @@ static MMergeGlobal *initialize_G_space(int n, Tree **forest)
244244
AllNodeHash *all_node;
245245
all_node = g->hash = new AllNodeHash;
246246

247-
tree = forest[0];
247+
int k = 0;
248+
// Allows to pad the array with NULLs, to always have the same trees at the same indices
249+
while (!forest[k]) k++;
250+
251+
tree = forest[k];
248252
n_leaf = tree->n_leaf;
249253
g->n_leaf = n_leaf;
250254
g->n_tree = n;
@@ -257,8 +261,13 @@ static MMergeGlobal *initialize_G_space(int n, Tree **forest)
257261
insert_single_leaf(all_node, n_leaf, name);
258262
root_an = 0;
259263
tree_index = 1;
260-
for (int k = 0; k < n; ++k, tree_index<<=1) {
264+
for (k = 0; k < n; ++k, tree_index<<=1) {
261265
tree = forest[k];
266+
// Allows to pad the array with NULLs, to always have the same trees at the same indices
267+
if (!tree) {
268+
fprintf(stderr, "[initialize_G_space] tree %d is NULL\n", k);
269+
continue;
270+
}
262271
// QC
263272
if (tree->n_leaf != n_leaf) {
264273
fprintf(stderr, "[initialize_G_space] tree %d has different number of leaves (%d!=%d)\n", k, tree->n_leaf, n_leaf);

0 commit comments

Comments
 (0)