Introduction
The c++ (cpp) tree_record example is extracted from the most popular open source projects, you can refer to the following example for usage.
Programming language: C++ (Cpp)
Class/type: tree_record
Example#1File:
trees-distances.CProject:
sibonli/BAli-Phy
int topology_distance2(const tree_record& t1, const tree_record& t2)
{
assert(t1.n_leaves() == t2.n_leaves());
unsigned n1 = t1.n_internal_branches();
unsigned n2 = t2.n_internal_branches();
// Accumulate distances for T1 partitions
unsigned shared=0;
int i=0,j=0;
while (1) {
if (i >= n1) break;
if (j >= n2) break;
if (t1.partitions[i] == t2.partitions[j]) {
i++;
j++;
shared++;
}
else if (t1.partitions[i] < t2.partitions[j])
i++;
else
j++;
}
return (n1-shared) + (n2-shared);
}
Example#2File:
tree-dist.CProject:
msuchard/BAli-Phy
int cmp(const tree_record& t1, const tree_record& t2)
{
int x = (int)t1.n_leaves() - (int)t2.n_leaves();
if (x != 0) return x;
x = (int)t1.n_internal_branches() - (int)t2.n_internal_branches();
if (x != 0) return x;
for(int i=0;i<t1.n_internal_branches();i++)
{
if (t1.partitions[i] == t2.partitions[i])
continue;
else if (t1.partitions[i] < t2.partitions[i])
return -1;
else
return 1;
}
return 0;
}