Skip to content

Commit

Permalink
Demo implementation of FileWriter
Browse files Browse the repository at this point in the history
  • Loading branch information
duizendnegen committed Nov 30, 2016
1 parent 0999439 commit 156c13b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions include/util/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ template <typename simple_type>
bool serializeVectorIntoAdjacencyArray(const std::string &filename,
const std::vector<std::vector<simple_type>> &data)
{
std::ofstream out_stream(filename, std::ios::binary);
storage::io::FileWriter file(filename, storage::io::FileWriter::HasNoFingerprint);

std::vector<std::uint32_t> offsets;
offsets.reserve(data.size() + 1);
std::uint64_t current_offset = 0;
Expand All @@ -64,18 +65,21 @@ bool serializeVectorIntoAdjacencyArray(const std::string &filename,
current_offset += vec.size();
offsets.push_back(boost::numeric_cast<std::uint32_t>(current_offset));
}
if (!serializeVector(out_stream, offsets))
return false;

std::vector<simple_type> all_data;
all_data.reserve(offsets.back());
for (auto const &vec : data)
all_data.insert(all_data.end(), vec.begin(), vec.end());

if (!serializeVector(out_stream, all_data))
return false;
if (!file.SerializeVector(offsets)) {
return false;
}

return static_cast<bool>(out_stream);
if (!file.SerializeVector(all_data)) {
return false;
}

return true;
}

template <typename simple_type, std::size_t WRITE_BLOCK_BUFFER_SIZE = 1024>
Expand Down

0 comments on commit 156c13b

Please sign in to comment.