Skip to content

Commit

Permalink
resolved issues with serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
riasc committed Oct 7, 2024
1 parent 67edc7e commit 5cfe73b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
7 changes: 4 additions & 3 deletions include/genogrove/IBPTree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

// Standard
#include <map>
#include <fstream>

// Class
#include "Node.hpp"
Expand Down Expand Up @@ -56,10 +57,10 @@ namespace genogrove {

void serialize(std::ostream& os) const;
IBPTree deserialize(std::istream& is);
void store(std::string filename);



/*
*
*/
void tree2SIF(std::string filename);

private:
Expand Down
15 changes: 8 additions & 7 deletions src/IBPTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,20 @@ namespace genogrove {
}

void IBPTree::serialize(std::ostream& os) const {
std::cout << "Serializing tree" << std::endl;
// write the order of the tree
os.write(reinterpret_cast<const char*>(&this->order), sizeof(this->order));

// write the root nodes
size_t numberRootNodes = this->rootnodes.size();
os.write(reinterpret_cast<const char*>(&numberRootNodes), sizeof(numberRootNodes));

// serialize the root noded
// serialize the rootnodes
for(const auto& [chr, rootnode] : this->rootnodes) {
size_t chrNameLength = chr.size();
os.write(reinterpret_cast<const char*>(&chrNameLength), sizeof(chrNameLength));
os.write(chr.c_str(), chrNameLength);

// serialize the rootnode and its subtree
rootnode->serialize(os);
os.write(chr.c_str(), chrNameLength); // write the chromosome name
rootnode->serialize(os); // serialize the rootnode and its subtree
}
}

Expand All @@ -169,7 +168,9 @@ namespace genogrove {
return tree;
}



void IBPTree::store(std::string filename) {
std::ofstream ofs(filename, std::ios::binary);
this->serialize(ofs);
}
} // namespace

0 comments on commit 5cfe73b

Please sign in to comment.