Skip to content

Commit c98f248

Browse files
committed
add some comments after discussion with Peter
1 parent ff92bb8 commit c98f248

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

core/species.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8781,6 +8781,15 @@ void Species::DerivedStatesFromMetadata(tsk_table_collection_t *p_tables)
87818781
// metadata column. To do this efficiently, without making copies of buffers, etc., we use a secondary
87828782
// mutation table with tsk_mutation_table_takeset_columns(), which is a bit tricky.
87838783

8784+
// This code might seem overly complex, but there are reasons. :-> Munging the tskit data structures more
8785+
// directly would not be safe, since tskit's internal implementation is not documented and is subject to
8786+
// change, which would risk breakage that might be silent. By using a temporary tsk_mutation_table_t with
8787+
// tsk_mutation_table_init() and tsk_mutation_table_takeset_columns(), we can get tskit to set things up for
8788+
// us. We still have to munge the internal data structures by swapping columns around with std::swap(), but
8789+
// that is relatively safe; it doesn't depend on how tskit is managing the internal state, it is just moving
8790+
// that internal state around from place to place. Still unsafe, but _less_ unsafe. To do this cleanly we
8791+
// would need new APIs added to tskit.
8792+
87848793
assert(p_tables != nullptr);
87858794

87868795
tsk_mutation_table_t &mutation_table = p_tables->mutations;
@@ -8845,6 +8854,15 @@ void Species::DerivedStatesToMetadata(tsk_table_collection_t *p_tables)
88458854
// Here we convert from our in-memory format by generating the ASCII column data, and then using a temporary
88468855
// mutation table with tsk_mutation_table_takeset_columns() to get the column in the right format for us.
88478856

8857+
// This code might seem overly complex, but there are reasons. :-> Munging the tskit data structures more
8858+
// directly would not be safe, since tskit's internal implementation is not documented and is subject to
8859+
// change, which would risk breakage that might be silent. By using a temporary tsk_mutation_table_t with
8860+
// tsk_mutation_table_init() and tsk_mutation_table_takeset_columns(), we can get tskit to set things up for
8861+
// us. We still have to munge the internal data structures by swapping columns around with std::swap(), but
8862+
// that is relatively safe; it doesn't depend on how tskit is managing the internal state, it is just moving
8863+
// that internal state around from place to place. Still unsafe, but _less_ unsafe. To do this cleanly we
8864+
// would need new APIs added to tskit.
8865+
88488866
assert(p_tables != nullptr);
88498867

88508868
tsk_mutation_table_t &mutation_table = p_tables->mutations;

0 commit comments

Comments
 (0)