Skip to content

Commit

Permalink
don't allow to change buffer size (bad logic)
Browse files Browse the repository at this point in the history
  • Loading branch information
karasikov committed Dec 11, 2020
1 parent 118a974 commit 021955e
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 48 deletions.
4 changes: 1 addition & 3 deletions include/sdsl/construct_lcp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,8 @@ void construct_lcp_PHI(cache_config& config)

// (4) Transform PLCP into LCP
std::string lcp_file = cache_file_name(conf::KEY_LCP, config);
size_type buffer_size = 1000000; // buffer_size is a multiple of 8!
int_vector_buffer<> lcp_buf(lcp_file, std::ios::out, buffer_size, lcp_width); // open buffer for lcp
int_vector_buffer<> lcp_buf(lcp_file, std::ios::out, 1024*1024, lcp_width); // open buffer for lcp
lcp_buf[0] = 0;
sa_buf.buffersize(buffer_size);
for (size_type i=1; i < n; ++i) {
size_type sai = sa_buf[i];
lcp_buf[i] = plcp[sai];
Expand Down
5 changes: 0 additions & 5 deletions include/sdsl/construct_sa_se.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ void _construct_sa_se(int_vector_type& text, std::string filename_sa, uint64_t s
bkt_s[i] = bkt_lms[i];
}
}
right.buffersize(0);
right.reset();
right_pointer = 0;
--left_pointer;
Expand Down Expand Up @@ -434,7 +433,6 @@ void _construct_sa_se(int_vector_type& text, std::string filename_sa, uint64_t s
}
}
util::clear(same_lms);
left.buffersize(0);
left.reset();

// Step 8 - Determine complete LMS order (recursivly)
Expand Down Expand Up @@ -484,15 +482,13 @@ void _construct_sa_se(int_vector_type& text, std::string filename_sa, uint64_t s
util::clear(lms_pos_b);
util::clear(isa_rec);
// write to left
left.buffersize(buffersize);
left_pointer = 0;
for (; left_pointer<number_of_lms_strings; ++left_pointer) {
left[left_pointer] = tmp_left[number_of_lms_strings-left_pointer-1];
}
left_pointer--;
util::clear(tmp_left);
} else {
left.buffersize(buffersize);
left_pointer = 0;
{
// load bit_vector lms_positions and create select support
Expand All @@ -519,7 +515,6 @@ void _construct_sa_se(int_vector_type& text, std::string filename_sa, uint64_t s
sdsl::remove(filename_text);

// Step 12 - Scan virtual array from left to right second time
right.buffersize(buffersize);
right_pointer = 0;
int_vector_buffer<> cached_sa(filename_sa, std::ios::out, buffersize, nsize);
size_t sa_pointer = 0;
Expand Down
25 changes: 7 additions & 18 deletions include/sdsl/int_vector_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class int_vector_buffer
* If true the file will be interpreted as plain array with t_width bits per integer.
* In second case (is_plain==true), t_width must be 8, 16, 32 or 64.
*/
int_vector_buffer(const std::string filename, std::ios::openmode mode=std::ios::in, const uint64_t buffer_size=1024*1024, const uint8_t int_width=t_width, const bool is_plain=false, const uint64_t file_offset=0)
int_vector_buffer(const std::string filename, std::ios::openmode mode=std::ios::in, uint64_t buffer_size=1024*1024, const uint8_t int_width=t_width, const bool is_plain=false, const uint64_t file_offset=0)
{
m_filename = filename;
assert(!(mode&std::ios::app));
Expand Down Expand Up @@ -177,7 +177,12 @@ class int_vector_buffer
assert(m_ifile->good());
m_size = size/width();
}
buffersize(buffer_size);

if (buffer_size < 8u)
buffer_size = 8; // at least 8 bytes
m_buffersize = ((buffer_size*8+width()-1)/width()+7)/8*8;
m_buffer = int_vector<t_width>(m_buffersize, 0, width());
read_block(0);
}

//! Move constructor.
Expand Down Expand Up @@ -224,22 +229,6 @@ class int_vector_buffer
return (m_buffersize*width())/8;
}

//! Set the buffersize in bytes
void buffersize(uint64_t buffersize)
{
if (0ULL == buffersize)
buffersize = 8;
write_block();
if (0==(buffersize*8)%width()) {
m_buffersize = buffersize*8/width(); // m_buffersize might not be multiple of 8, but m_buffersize*width() is.
} else {
uint64_t element_buffersize = (buffersize*8)/width()+1; // one more element than fits into given buffersize in byte
m_buffersize = element_buffersize+7 - (element_buffersize+7)%8; // take next multiple of 8
}
m_buffer = int_vector<t_width>(m_buffersize, 0, width());
if (0!=m_buffersize) read_block(0);
}

//! Returns whether state of underlying streams are good
bool good()
{
Expand Down
8 changes: 3 additions & 5 deletions include/sdsl/lcp_support_tree2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ class _lcp_support_tree2
{
m_cst = cst;

int_vector_buffer<> lcp_buf(cache_file_name(conf::KEY_LCP, config));
size_type buf_len = 1000000;
int_vector_buffer<> lcp_buf(cache_file_name(conf::KEY_LCP, config), std::ios::in, buf_len);
std::string bwt_file = cache_file_name(key_trait<t_cst::csa_type::alphabet_type::int_width>::KEY_BWT, config);
int_vector_buffer<t_cst::csa_type::alphabet_type::int_width> bwt_buf(bwt_file);
int_vector_buffer<t_cst::csa_type::alphabet_type::int_width> bwt_buf(bwt_file, std::ios::in, buf_len);

std::string sml_lcp_file = tmp_file(config, "_fc_lf_lcp_sml");
std::string big_lcp_file = tmp_file(config, "_fc_lf_lcp_big");
Expand Down Expand Up @@ -206,9 +207,6 @@ void construct_first_child_and_lf_lcp(int_vector_buffer<>& lcp_buf,
{
typedef int_vector<>::size_type size_type;
const size_type M = 255; // limit for values represented in the small LCP part
size_type buf_len = 1000000;
lcp_buf.buffersize(buf_len);
bwt_buf.buffersize(buf_len);
size_type n = lcp_buf.size();

osfstream sml_lcp_out(small_lcp_file, std::ios::out | std::ios::trunc | std::ios::binary);
Expand Down
5 changes: 2 additions & 3 deletions lib/construct_lcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ namespace sdsl
void construct_lcp_semi_extern_PHI(cache_config& config)
{
typedef int_vector<>::size_type size_type;
int_vector_buffer<> sa_buf(cache_file_name(conf::KEY_SA, config));
size_type buffer_size = 4000000; // buffer_size is a multiple of 8!
int_vector_buffer<> sa_buf(cache_file_name(conf::KEY_SA, config), std::ios::in, buffer_size);
size_type n = sa_buf.size();
if (1==n) {
int_vector<> lcp(1, 0);
Expand Down Expand Up @@ -57,8 +58,6 @@ void construct_lcp_semi_extern_PHI(cache_config& config)
}
}

size_type buffer_size = 4000000; // buffer_size is a multiple of 8!
sa_buf.buffersize(buffer_size);
int_vector_buffer<> lcp_out_buf(cache_file_name(conf::KEY_LCP, config), std::ios::out, buffer_size, sa_buf.width()); // open buffer for plcp

for (size_type i=0, sai_1=0,l=0, sai=0,iq=0; i < n; ++i) {
Expand Down
1 change: 0 additions & 1 deletion lib/construct_sa_se.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ void _construct_sa_IS(int_vector<> &text, int_vector<> &sa, std::string& filenam
bkt[c] = bkt[c-1]+c_array[c];
}
c_array.close();
c_array.buffersize(0);

for (size_t i=n-1, endpointer=n; i<n; --i) {
if (sa[i]>0) {
Expand Down
13 changes: 0 additions & 13 deletions test/int_vector_buffer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,19 +335,6 @@ void test_random_access(size_type width=1)
ASSERT_EQ(i & sdsl::bits::lo_set[ivb.width()], (size_type)ivb[i]);
}
}
// Test random access with different buffersize
buffersize = 50;
ivb.buffersize(buffersize);
ASSERT_EQ((size_type)1000, ivb.size());
for (size_type i=0; i < 1000; ++i) {
value_type x = dice();
ivb[x] = x & sdsl::bits::lo_set[ivb.width()];
}
for (size_type i=0; i < ivb.size(); ++i) {
if (ivb[i]) {
ASSERT_EQ(i & sdsl::bits::lo_set[ivb.width()], (size_type)ivb[i]);
}
}
// Test random access read
for (size_type i=0; i < ivb.size(); ++i) {
value_type idx = dice();
Expand Down

0 comments on commit 021955e

Please sign in to comment.