Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #339 #340

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion include/sdsl/int_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,9 @@ class int_vector
// Write data (without header) to a stream.
size_type write_data(std::ostream& out) const;

// Write raw data (without header) to a stream.
size_type write_raw_data(std::ostream& out) const;

//! Serializes the int_vector to a stream.
/*! \return The number of bytes written to out.
* \sa load
Expand Down Expand Up @@ -601,6 +604,7 @@ class int_vector


struct raw_wrapper {
typedef int_vector::size_type size_type;
const int_vector& vec;
raw_wrapper() = delete;
raw_wrapper(const int_vector& _vec) : vec(_vec) {}
Expand All @@ -609,7 +613,7 @@ class int_vector
serialize(std::ostream& out, structure_tree_node* v=nullptr, std::string name="")const
{
structure_tree_node* child = structure_tree::add_child(v, name, util::class_name(*this));
auto written_bytes = vec.write_data(out);
auto written_bytes = vec.write_raw_data(out);
structure_tree::add_size(child, written_bytes);
return written_bytes;
}
Expand Down Expand Up @@ -1520,6 +1524,25 @@ typename int_vector<t_width>::size_type int_vector<t_width>::write_data(std::ost
return written_bytes;
}

template<uint8_t t_width>
typename int_vector<t_width>::size_type int_vector<t_width>::write_raw_data(std::ostream& out) const
{
typedef typename int_vector<t_width>::value_type value_type;
size_type written_bytes = 0;
uint64_t* p = m_data;
size_type idx = 0; // uin64_t index
while (idx+conf::SDSL_BLOCK_SIZE < ((width()*size())>>6)) {
out.write((char*) p, conf::SDSL_BLOCK_SIZE*sizeof(uint64_t));
written_bytes += conf::SDSL_BLOCK_SIZE*sizeof(uint64_t);
p += conf::SDSL_BLOCK_SIZE;
idx += conf::SDSL_BLOCK_SIZE;
}
uint64_t remaining_elements = (width()*size())/(8*sizeof(value_type))-(idx/sizeof(value_type));
out.write((char*) p, remaining_elements*sizeof(value_type));
written_bytes += remaining_elements*sizeof(value_type);
return written_bytes;
}

template<uint8_t t_width>
typename int_vector<t_width>::size_type int_vector<t_width>::serialize(std::ostream& out,
structure_tree_node* v,
Expand Down