-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNode.cpp
84 lines (83 loc) · 1.85 KB
/
Node.cpp
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
#include "Node.h"
#include <iostream>
#include <stdlib.h>
#include <limits.h>
#include<string>
#include<sstream>
//null constructors
Node::Node(){
float t_event= INT_MAX;
this->parent=nullptr;
this->rchild=nullptr;
this->lchild=nullptr;
}
//simple constructor
Node::Node(float birth, float death){
//set all pointers to null
this->parent=nullptr;
this->rchild=nullptr;
this->lchild=nullptr;
//set rates
this->birth_rate = birth;
this->death_rate = death;
}
//constructor inheriting rates from parent
Node::Node(Node * ancestor){
//inherit rates from parent
this->birth_rate = ancestor->birth_rate;
this->death_rate = ancestor->death_rate;
//set parent
this->parent=ancestor;
//set child pointers to null
this->rchild=nullptr;
this->lchild=nullptr;
}
//methods
bool Node::hasChild(){
bool flag = 0;
if(this->lchild != nullptr | this->rchild!=nullptr){
flag=1;
}
return(flag);
}
//setter for event time
void Node::set_event_time(float tau){
this->t_event = tau;
}
//getter for total rate
float Node::get_rate(){
return(this->birth_rate + this->death_rate);
}
//setter for total rate
float Node::get_event_time(){
return(this->t_event);
}
std::string Node::print_addr(){
std::stringstream ss;
ss << (void const *)this;
return(ss.str());
}
void Node::set_left_child(Node * n){
this->lchild = n;
}
void Node::set_right_child(Node *n){
this->rchild = n;
}
void Node::set_parent(Node*n){
this->parent = n;
}
Node * Node::get_left_child(){
return(this->lchild);
}
Node * Node::get_right_child(){
return(this->rchild);
}
Node * Node::get_parent(){
return(this->parent);
}
float Node::get_brlen(){
return(brlen);
}
void Node::set_brlen(float len){
this->brlen = len;
};