src/matOptimize/detailed_mutations_load_store.cpp
//serialize each node recursively, post-order traversl, so parent node know the offset of its children
serialize each node recursively, post-order traversl, so parent node know the offset of its children
serialize each node recursively post - order traversl so parent node know the offset of its children
static std::pair<u_int64_t, u_int64_t> write_subtree(MAT::Node *root,const MAT::Tree& tree,
        std::ofstream &outfile) {
    std::vector<u_int64_t> children_offset;
    std::vector<u_int64_t> children_length;
    Mutation_Detailed::node this_node;
    for (auto child : root->children) {
        auto temp = write_subtree(child, tree,outfile);
        this_node.add_children_offsets(temp.first);
        this_node.add_children_lengths(temp.second);
    }
    this_node.set_identifier(root->identifier);
    for(const auto& mut:root->mutations) {
        auto serialized_mut=this_node.add_node_mutations();
        serialize_mutation(mut, serialized_mut);
    }
    auto condensed_node_iter=tree.condensed_nodes.find(root->identifier);
    if(condensed_node_iter!=tree.condensed_nodes.end()) {
        for(const auto& child_id:condensed_node_iter->second) {
            this_node.add_condensed_nodes(child_id);
        }
    }
    u_int64_t start = outfile.tellp();
    this_node.SerializeToOstream(&outfile);
    u_int64_t end = outfile.tellp();
    return std::make_pair(start, end - start);
}
static std :: pair < u_int64_t , u_int64_t > write_subtree ( MAT :: Node * root , const MAT :: Tree & tree , std :: ofstream & outfile ) { std :: vector < u_int64_t > children_offset ; std :: vector < u_int64_t > children_length ; Mutation_Detailed :: node this_node ; for ( auto child : root -> children ) { auto temp = write_subtree ( child , tree , outfile ) ; this_node . add_children_offsets ( temp . first ) ; this_node . add_children_lengths ( temp . second ) ; } this_node . set_identifier ( root -> identifier ) ; for ( const auto & mut : root -> mutations ) { auto serialized_mut = this_node . add_node_mutations ( ) ; serialize_mutation ( mut , serialized_mut ) ; } auto condensed_node_iter = tree . condensed_nodes . find ( root -> identifier ) ; if ( condensed_node_iter != tree . condensed_nodes . end ( ) ) { for ( const auto & child_id : condensed_node_iter -> second ) { this_node . add_condensed_nodes ( child_id ) ; } } u_int64_t start = outfile . tellp ( ) ; this_node . SerializeToOstream ( & outfile ) ; u_int64_t end = outfile . tellp ( ) ; return std :: make_pair ( start , end - start ) ; }
serialize each node recursively, post-order traversl, so parent node know the offset of its children
serialize each node recursively post - order traversl so parent node know the offset of its children