@@ -550,30 +550,37 @@ void MashPlacement::KPlacementDeviceArrays::printTree(std::vector<std::string> n
550550 double *h_len = new double [numSequences * 8 ];
551551 double *h_closest_dis = new double [numSequences * 20 ];
552552 int *h_closest_id = new int [numSequences * 20 ];
553- std::function<void (int , int )> print = [&](int node, int from)
554- {
555- if (h_nxt[h_head[node]] != -1 )
556- {
557- // printf("(");
553+ std::function<void (int ,int )> print = [&](int node, int from) {
554+ if (h_nxt[h_head[node]] != -1 ) {
558555 output_ << " (" ;
559- std::vector<int > pos;
560- for (int i = h_head[node]; i != -1 ; i = h_nxt[i])
561- if (h_e[i] != from)
562- pos.push_back (i);
563- for (size_t i = 0 ; i < pos.size (); i++)
564- {
565- print (h_e[pos[i]], node);
566- // printf(":");
567- // printf("%.5g%c",h_len[pos[i]],i+1==pos.size()?')':',');
556+ std::vector<std::pair<int ,int >> pos; // {edge_index, parent_node}
557+ for (int i = h_head[node]; i != -1 ; i = h_nxt[i]) {
558+ if (h_e[i] != from) {
559+ if (h_len[i] == 0 ) {
560+ int collapsed = h_e[i];
561+ if (h_head[collapsed] != -1 ) {
562+ for (int j = h_head[collapsed]; j != -1 ; j = h_nxt[j]) {
563+ if (h_e[j] != node) {
564+ pos.push_back ({j, collapsed});
565+ }
566+ }
567+ }
568+ } else {
569+ pos.push_back ({i, node});
570+ }
571+ }
572+ }
573+ for (size_t i = 0 ; i < pos.size (); i++) {
574+ auto [edgeIdx, parent] = pos[i];
575+ print (h_e[edgeIdx], parent);
568576 output_ << " :" ;
569- // output_ << "%.5g%c",h_len[pos[i]],i+1==pos.size()?')':',';
570- output_ << h_len[pos[i]] << (i + 1 == pos.size () ? ' )' : ' ,' );
577+ output_ << h_len[edgeIdx] << (i+1 == pos.size () ? ' )' : ' ,' );
571578 }
572- }
573- // else std::cout<<name[node];
574- else
579+ } else {
575580 output_ << name[node];
581+ }
576582 };
583+
577584 for (int i = 0 ; i < numSequences * 2 ; ++i)
578585 {
579586 h_head[i] = d_head[i];
0 commit comments