creating PTrees and getting their total counts now working
git-svn-id: svn://anubis/gvsu@302 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
parent
12a4d54bcc
commit
85ce8d7ca8
@ -32,6 +32,7 @@ PTree::PTree(const vector<Sequence *> & leaves)
|
||||
(*myLevels[level_index-1])[2*i+1]
|
||||
);
|
||||
}
|
||||
myLevels.push_back(level);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -49,6 +50,7 @@ void PTree::print(ostream & out, int level, int index,
|
||||
{
|
||||
out << prefix;
|
||||
out << myLevels[level][0][index];
|
||||
out << endl;
|
||||
if (level > 0)
|
||||
{
|
||||
print(out, level - 1, index * 2, subprefix + "+-", subprefix + "| ");
|
||||
@ -61,3 +63,16 @@ ostream & operator<<(ostream & out, const PTree & p)
|
||||
p.print(out, p.myLevels.size() - 1, 0, "", "");
|
||||
return out;
|
||||
}
|
||||
|
||||
int PTree::getCount()
|
||||
{
|
||||
int count = 0;
|
||||
for (int i = 0, levels = myLevels.size(); i < levels; i++)
|
||||
{
|
||||
for (int j = 0, l_size = myLevels[i][0].size(); j < l_size; j++)
|
||||
{
|
||||
count += myLevels[i][0][j].getCount();
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ public:
|
||||
~PTree();
|
||||
void print(std::ostream & out, int level, int index,
|
||||
std::string prefix, std::string subprefix) const;
|
||||
int getCount();
|
||||
|
||||
friend std::ostream & operator<<(std::ostream & out, const PTree & p);
|
||||
};
|
||||
|
@ -17,6 +17,7 @@ public:
|
||||
Sequence(int size);
|
||||
Sequence(const char * initializer);
|
||||
Sequence parent(const Sequence & other);
|
||||
int getCount() { return myMutationCount; }
|
||||
|
||||
friend std::ostream & operator<<(std::ostream & out, const Sequence & s);
|
||||
};
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include "Sequence.h"
|
||||
#include "PTree.h"
|
||||
using namespace std;
|
||||
|
||||
void usage()
|
||||
@ -88,11 +89,10 @@ int main(int argc, char * argv[])
|
||||
|
||||
close(fd);
|
||||
|
||||
cout << "Found " << sequences.size() << " sequences:" << endl;
|
||||
for (int i = 0, sz = sequences.size(); i < sz; i++)
|
||||
{
|
||||
cout << *sequences[i] << endl;
|
||||
}
|
||||
PTree tree(sequences);
|
||||
cout << "tree:" << endl;
|
||||
cout << tree;
|
||||
cout << endl << "total count: " << tree.getCount() << endl;
|
||||
|
||||
MPI_Finalize();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user