File: Node.cpp

package info (click to toggle)
clustalx 2.1%2Blgpl-5
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,868 kB
  • sloc: cpp: 40,050; sh: 163; xml: 102; makefile: 15
file content (116 lines) | stat: -rw-r--r-- 2,310 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#ifdef HAVE_CONFIG_H
    #include "config.h"
#endif
#include "Node.h"
#include "../../general/VectorUtility.h"
#include "../../general/debuglogObject.h"
#include "../../general/clustalw.h"
#include <iostream>
#include <sstream>
namespace clustalw

{

Node::Node(int _seqNum, double *dists, int numDist)
    : next(0),
      left(0),
      right(0),
      size(1),
      seqNum(_seqNum),
      height(0.0),
      ptrToDistMatRow(dists),
      minDist(numeric_limits<double>::max()),
      indexToMinDist(-1),
      numDists(numDist),
      order(0)
{
    allElements.resize(1);
    allElements[0] = seqNum;
                    
    if (ptrToDistMatRow)
    {
        findMinDist();
    }
}


void Node::merge(Node **rightNode, double _height)
{
    left = new Node(*this);
    right = *rightNode;

    left->ptrToDistMatRow = 0;
    size = left->size + right->size;
    seqNum = -1;
    height = _height;
    left->height = height;
    right->height = height;
    
    vectorutils::mergeVectors(&allElements, &(right->allElements));
    right->allElements.clear();      
    
    if (next == right)
    {
        next = right->next;
    }
    else
    {    
        *rightNode = right->next;
    }
}


void Node::findMinDist()
{    
    double *distIterator = ptrToDistMatRow;
    double *minDistSoFar = distIterator++;
    
    // We search from the end of our area of the array       
    for(int i = numDists; --i; distIterator++) // When --i gets to zero it will stop
    {    
        if ((*distIterator >= 0) && (*distIterator < *minDistSoFar))
        {
            minDistSoFar = distIterator;
        }
    }
    
    minDist = *minDistSoFar;
    indexToMinDist = minDistSoFar - ptrToDistMatRow;
}
 
void Node::printElements()
{
    for(int i = 0; i < (int)allElements.size(); i++)
    {
        cout << " " << allElements[i];
    }
    cout << "\n";               
}

string Node::elementsToString()
{
    ostringstream elems;
    for(int i = 0; i < (int)allElements.size(); i++)
    {
        elems << " " << allElements[i];
    }
    return elems.str();
}

void Node::makeEmpty()
{
    makeEmpty(this);
}

void Node::makeEmpty(Node* t)
{
    if(t != 0)
    {
        makeEmpty(t->left);
        makeEmpty(t->right);
        delete t;
    }
    t = 0;
}
                                           
}