Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions c/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
- Add ``edge`` attribute to ``mutation_t`` struct make available in tree sequence.
(:user:`jeromekelleher`, :issue:`685`, :pr:`2279`)

- Reduce peak memory usage in ``tsk_treeseq_simplify``.
(:user:`jeromekelleher`, :issue:`2287`, :pr:`2288`)

----------------------
[0.99.15] - 2021-12-07
----------------------
Expand Down
21 changes: 15 additions & 6 deletions c/tskit/trees.c
Original file line number Diff line number Diff line change
Expand Up @@ -3227,20 +3227,29 @@ tsk_treeseq_simplify(const tsk_treeseq_t *self, const tsk_id_t *samples,
tsk_id_t *node_map)
{
int ret = 0;
tsk_table_collection_t tables;
tsk_table_collection_t *tables = tsk_malloc(sizeof(*tables));

ret = tsk_treeseq_copy_tables(self, &tables, 0);
if (tables == NULL) {
ret = TSK_ERR_NO_MEMORY;
goto out;
}
ret = tsk_treeseq_copy_tables(self, tables, 0);
if (ret != 0) {
goto out;
}
ret = tsk_table_collection_simplify(
&tables, samples, num_samples, options, node_map);
ret = tsk_table_collection_simplify(tables, samples, num_samples, options, node_map);
if (ret != 0) {
goto out;
}
ret = tsk_treeseq_init(output, &tables, TSK_TS_INIT_BUILD_INDEXES);
ret = tsk_treeseq_init(
output, tables, TSK_TS_INIT_BUILD_INDEXES | TSK_TAKE_OWNERSHIP);
/* Once tsk_tree_init has returned ownership of tables is transferred */
tables = NULL;
out:
tsk_table_collection_free(&tables);
if (tables != NULL) {
tsk_table_collection_free(tables);
tsk_safe_free(tables);
}
return ret;
}

Expand Down