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

make wt_int and wm_int thread safe #264

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
24 changes: 3 additions & 21 deletions include/sdsl/wm_int.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ class wm_int
uint32_t m_max_level = 0;
int_vector<64> m_zero_cnt; // m_zero_cnt[i] contains the number of zeros in level i
int_vector<64> m_rank_level; // m_rank_level[i] contains m_tree_rank(i*size())
mutable int_vector<64> m_path_off; // array keeps track of path offset in select-like methods
mutable int_vector<64> m_path_rank_off;// array keeps track of rank values for the offsets

void copy(const wm_int& wt) {
m_size = wt.m_size;
Expand All @@ -111,15 +109,6 @@ class wm_int
m_max_level = wt.m_max_level;
m_zero_cnt = wt.m_zero_cnt;
m_rank_level = wt.m_rank_level;
m_path_off = wt.m_path_off;
m_path_rank_off = wt.m_path_rank_off;
}

private:

void init_buffers(uint32_t max_level) {
m_path_off = int_vector<64>(max_level+1);
m_path_rank_off = int_vector<64>(max_level+1);
}

public:
Expand All @@ -129,9 +118,7 @@ class wm_int
const uint32_t& max_level = m_max_level; //!< Maximal level of the wavelet tree.

//! Default constructor
wm_int() {
init_buffers(m_max_level);
};
wm_int() { };

//! Semi-external constructor
/*! \param buf File buffer of the int_vector for which the wm_int should be build.
Expand All @@ -146,7 +133,6 @@ class wm_int
template<uint8_t int_width>
wm_int(int_vector_buffer<int_width>& buf, size_type size,
uint32_t max_level=0) : m_size(size) {
init_buffers(m_max_level);
if (0 == m_size)
return;
size_type n = buf.size(); // set n
Expand All @@ -170,7 +156,6 @@ class wm_int
} else {
m_max_level = max_level;
}
init_buffers(m_max_level);


std::string tree_out_buf_file_name = tmp_file(buf.filename(), "_m_tree");
Expand Down Expand Up @@ -263,8 +248,6 @@ class wm_int
m_max_level = std::move(wt.m_max_level);
m_zero_cnt = std::move(wt.m_zero_cnt);
m_rank_level = std::move(wt.m_rank_level);
m_path_off = std::move(wt.m_path_off);
m_path_rank_off = std::move(wt.m_path_rank_off);
}
return *this;
}
Expand All @@ -281,8 +264,6 @@ class wm_int
std::swap(m_max_level, wt.m_max_level);
m_zero_cnt.swap(wt.m_zero_cnt);
m_rank_level.swap(wt.m_rank_level);
m_path_off.swap(wt.m_path_off);
m_path_rank_off.swap(wt.m_path_rank_off);
}
}

Expand Down Expand Up @@ -395,6 +376,8 @@ class wm_int
size_type select(size_type i, value_type c)const {
assert(1 <= i and i <= rank(size(), c));
uint64_t mask = 1ULL << (m_max_level-1);
int_vector<64> m_path_off(max_level+1);
int_vector<64> m_path_rank_off(max_level+1);
m_path_off[0] = m_path_rank_off[0] = 0;
size_type b = 0; // start position of the interval
size_type r = i;
Expand Down Expand Up @@ -544,7 +527,6 @@ class wm_int
read_member(m_max_level, in);
m_zero_cnt.load(in);
m_rank_level.load(in);
init_buffers(m_max_level);
}

//! Represents a node in the wavelet tree
Expand Down
23 changes: 4 additions & 19 deletions include/sdsl/wt_int.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ class wt_int
select_1_type m_tree_select1; // select support for the wavelet tree bit vector
select_0_type m_tree_select0;
uint32_t m_max_level = 0;
mutable int_vector<64> m_path_off; // array keeps track of path offset in select-like methods
mutable int_vector<64> m_path_rank_off;// array keeps track of rank values for the offsets

void copy(const wt_int& wt) {
m_size = wt.m_size;
Expand All @@ -102,17 +100,10 @@ class wt_int
m_tree_select0 = wt.m_tree_select0;
m_tree_select0.set_vector(&m_tree);
m_max_level = wt.m_max_level;
m_path_off = wt.m_path_off;
m_path_rank_off = wt.m_path_rank_off;
}

private:

void init_buffers(uint32_t max_level) {
m_path_off = int_vector<64>(max_level+1);
m_path_rank_off = int_vector<64>(max_level+1);
}

// recursive internal version of the method interval_symbols
void _interval_symbols(size_type i, size_type j, size_type& k,
std::vector<value_type>& cs,
Expand Down Expand Up @@ -162,9 +153,7 @@ class wt_int
const uint32_t& max_level = m_max_level; //!< Maximal level of the wavelet tree.

//! Default constructor
wt_int() {
init_buffers(m_max_level);
};
wt_int() { };

//! Semi-external constructor
/*! \param buf File buffer of the int_vector for which the wt_int should be build.
Expand All @@ -179,7 +168,7 @@ class wt_int
template<uint8_t int_width>
wt_int(int_vector_buffer<int_width>& buf, size_type size,
uint32_t max_level=0) : m_size(size) {
init_buffers(m_max_level);
//init_buffers(m_max_level);
if (0 == m_size)
return;
size_type n = buf.size(); // set n
Expand All @@ -202,7 +191,6 @@ class wt_int
} else {
m_max_level = max_level;
}
init_buffers(m_max_level);

// buffer for elements in the right node
int_vector_buffer<> buf1(tmp_file(buf.filename(), "_wt_constr_buf"),
Expand Down Expand Up @@ -298,8 +286,6 @@ class wt_int
m_tree_select0 = std::move(wt.m_tree_select0);
m_tree_select0.set_vector(&m_tree);
m_max_level = std::move(wt.m_max_level);
m_path_off = std::move(wt.m_path_off);
m_path_rank_off = std::move(wt.m_path_rank_off);
}
return *this;
}
Expand All @@ -314,8 +300,6 @@ class wt_int
util::swap_support(m_tree_select1, wt.m_tree_select1, &m_tree, &(wt.m_tree));
util::swap_support(m_tree_select0, wt.m_tree_select0, &m_tree, &(wt.m_tree));
std::swap(m_max_level, wt.m_max_level);
m_path_off.swap(wt.m_path_off);
m_path_rank_off.swap(wt.m_path_rank_off);
}
}

Expand Down Expand Up @@ -444,6 +428,8 @@ class wt_int
size_type offset = 0;
uint64_t mask = (1ULL) << (m_max_level-1);
size_type node_size = m_size;
int_vector<64> m_path_off(max_level+1);
int_vector<64> m_path_rank_off(max_level+1);
m_path_off[0] = m_path_rank_off[0] = 0;

for (uint32_t k=0; k < m_max_level and node_size; ++k) {
Expand Down Expand Up @@ -727,7 +713,6 @@ class wt_int
m_tree_select1.load(in, &m_tree);
m_tree_select0.load(in, &m_tree);
read_member(m_max_level, in);
init_buffers(m_max_level);
}

//! Represents a node in the wavelet tree
Expand Down