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

General performance improvements #200

Open
wants to merge 2 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
2 changes: 1 addition & 1 deletion include/sdsl/bit_vector_il.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class bit_vector_il
size_type cum_sum = 0;
size_type sample_rate = t_bs/64;
for (size_type i=0, sample_cnt=sample_rate; i < blocks; ++i, ++sample_cnt) {
if (sample_cnt == sample_rate) {
if (sample_cnt == sample_rate) { // TODO get rid of this branch
m_data[j] = cum_sum;
sample_cnt = 0;
j++;
Expand Down
8 changes: 4 additions & 4 deletions include/sdsl/bp_support_sada.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ class bp_support_sada
// calculate min/max excess values of the small blocks and medium blocks
difference_type min_ex = 1, max_ex = -1, curr_rel_ex = 0, curr_abs_ex = 0;
for (size_type i=0; i < m_size; ++i) {
if ((*bp)[i])
if ((*bp)[i]) // TODO This is not good
++curr_rel_ex;
else
--curr_rel_ex;
Expand Down Expand Up @@ -397,9 +397,9 @@ class bp_support_sada

for (size_type v = m_med_block_min_max.size()/2 - 1; !is_root(v); --v) {
size_type p = parent(v);
if (min_value(v) < min_value(p)) // update minimum
if (min_value(v) < min_value(p)) // update minimum TODO branch can be avoided
m_med_block_min_max[2*p] = m_med_block_min_max[2*v];
if (max_value(v) > max_value(p)) // update maximum
if (max_value(v) > max_value(p)) // update maximum TODO branch can be avoided
m_med_block_min_max[2*p+1] = m_med_block_min_max[2*v+1];
}
}
Expand Down Expand Up @@ -648,7 +648,7 @@ class bp_support_sada
l_sblock = 1;
}
for (size_type i=l_sblock; i <= r_sblock; ++i) {
if ((e = (excess(i*t_sml_blk-1) + sml_min_value(i))) <= min_ex) {
if ((e = (excess(i*t_sml_blk-1) + sml_min_value(i))) <= min_ex) { //TODO branch can be avoided
pos_min_block = i;
min_ex = e;
}
Expand Down
2 changes: 1 addition & 1 deletion include/sdsl/coder_comma.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ inline uint64_t comma<t_width>::decode(const uint64_t* data,
digit = (uint32_t)bits::read_int_and_move(data, offset, t_width)); //and read next digit
//now decide how to handle value
value = (t_sumup) ? value + v : v;
if (t_inc) *(it++) = value;
if (t_inc) *(it++) = value; // TODO can be done without the branch
}
return value;
}
Expand Down
4 changes: 2 additions & 2 deletions include/sdsl/coder_elias_delta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ bool elias_delta::encode(const int_vector& v, int_vector& z)
uint64_t w;
const uint64_t zero_val = v.width() < 64 ? (1ULL)<<v.width() : 0;
for (typename int_vector::const_iterator it = v.begin(), end = v.end(); it != end; ++it) {
if ((w=*it) == 0) {
if ((w=*it) == 0) { // TODO get rid of this branch
w = zero_val;
}
z_bit_size += encoding_length(w);
Expand All @@ -176,7 +176,7 @@ bool elias_delta::encode(const int_vector& v, int_vector& z)
size_type len, len_1_len; // TODO: change to uint8_t and test it
for (typename int_vector::const_iterator it = v.begin(), end=v.end(); it != end; ++it) {
w = *it;
if (w == 0) {
if (w == 0) { // TODO get rid of this branch
w = zero_val;
}
// (number of bits to represent w)
Expand Down
10 changes: 5 additions & 5 deletions include/sdsl/coder_elias_gamma.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ bool elias_gamma::encode(const int_vector& v, int_vector& z)
uint64_t w;
const uint64_t zero_val = v.width() < 64 ? (1ULL)<<v.width() : 0;
for (typename int_vector::const_iterator it = v.begin(), end = v.end(); it != end; ++it) {
if ((w=*it) == 0) {
if ((w=*it) == 0) { // TODO not necessary
w = zero_val;
}
z_bit_size += encoding_length(w);
Expand All @@ -172,19 +172,19 @@ bool elias_gamma::encode(const int_vector& v, int_vector& z)
size_type len_1; // TODO: change to uint8_t and test it
for (typename int_vector::const_iterator it = v.begin(), end=v.end(); it != end; ++it) {
w = *it;
if (w == 0) {
if (w == 0) { // TODO not necessary
w = zero_val;
}
// (number of bits to represent w)-1
if (!w) {
if (!w) { // TODO get rid of this branch
len_1 = 64;
bits::write_int_and_move(z_data, 0ULL, offset, 64);
bits::write_int_and_move(z_data, 1ULL, offset, 1);
} else {
} else { // TODO get rid of this branch
len_1 = bits::hi(w);
bits::write_int_and_move(z_data, 1ULL << len_1, offset, len_1+1);
}
if (len_1) {
if (len_1) { // TODO get rid of this branch
bits::write_int_and_move(z_data, w, offset, len_1);
}
}
Expand Down
10 changes: 5 additions & 5 deletions include/sdsl/coder_fibonacci.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ class fibonacci

impl() {
for (uint32_t x=0; x <= 0x1FFF; ++x) {
if (bits::cnt11(x)) {
if (bits::cnt11(x)) { // TODO get rid of this branch
fib2bin_shift[x] = bits::sel11(x, 1)+1;
} else {
} else { // TODO get rid of this branch
fib2bin_shift[x] = 0;
}
}
Expand Down Expand Up @@ -169,8 +169,8 @@ inline bool fibonacci::encode(const int_vector1& v, int_vector2& z)
uint64_t w;
const uint64_t zero_val = v.width() < 64 ? (1ULL)<<v.width() : 0;
for (typename int_vector1::const_iterator it=v.begin(), end = v.end(); it != end; ++it) {
if ((w=*it) == 0) {
if (v.width() < 64) {
if ((w=*it) == 0) { // TODO unnecessary branch
if (v.width() < 64) { // TODO unnecessary branch
w = zero_val;
}
}
Expand All @@ -186,7 +186,7 @@ inline bool fibonacci::encode(const int_vector1& v, int_vector2& z)
uint64_t t;
for (typename int_vector1::const_iterator it=v.begin(), end = v.end(); it != end; ++it) {
w = *it;
if (w == 0) {
if (w == 0) { // TODO unnecessary branch
w = zero_val;
}
int8_t len_1 = encoding_length(w)-1,j;
Expand Down
4 changes: 2 additions & 2 deletions include/sdsl/construct_lcp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void construct_lcp_kasai(cache_config& config)
sa_1 = isa_buf[i]; // = isa[i]
if (sa_1) {
j = sa[sa_1-1];
if (l) --l;
if (l) --l; // TODO l changes in the else, could be unpredictable
assert(i!=j);
while (text[i+l]==text[j+l]) { // i+l < n and j+l < n are not necessary, since text[n]=0 and text[i]!=0 (i<n) and i!=j
++l;
Expand Down Expand Up @@ -158,7 +158,7 @@ void construct_lcp_PHI(cache_config& config)
++l;
}
plcp[i] = l;
if (l) {
if (l) { // TODO possible without the branch
max_l = std::max(max_l, l);
--l;
}
Expand Down
25 changes: 13 additions & 12 deletions include/sdsl/construct_sa_se.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,10 @@ void _construct_sa_se(int_vector_type& text, std::string filename_sa, uint64_t s
bkt_s_last=0, bkt_s_sum=0;
for (size_t i=0; i<sigma; ++i) {
bkt_s_sum += bkt_s[i];
if (bkt_s[i]) {
if (bkt_s[i]) { // TODO possible without the branch
bkt_s[i] = bkt_s_sum;
bkt_s_last = bkt_s_sum;
} else {
} else { // TODO possible without the branch
bkt_s[i] = bkt_s_sum;
}
bkt_lms[i] = bkt_s[i];
Expand Down Expand Up @@ -348,7 +348,7 @@ void _construct_sa_se(int_vector_type& text, std::string filename_sa, uint64_t s
++a;
++b;
}
if (text[a] == text[b]) {
if (text[a] == text[b]) { // TODO possible without conditional
same_lms[i] = true;
--order;
}
Expand All @@ -373,17 +373,17 @@ void _construct_sa_se(int_vector_type& text, std::string filename_sa, uint64_t s
util::_set_zero_bits(text_rec);
order = 0;
for (size_t i=number_of_lms_strings-1; i<number_of_lms_strings; --i) {
if (!same_lms[i]) {
if (!same_lms[i]) { // TODO possible without conditional
++order;
}
if (left[i]/2 >= size_of_part) {
if (left[i]/2 >= size_of_part) { // TODO possible without conditional
text_rec[(left[i]/2)-size_of_part] = order;
}
}
std::string filename_text_rec_part2 = tmp_file(filename_sa, "_text_rec_part2"+util::to_string(recursion));
size_t pos = 0;
for (size_t i=0; i<size_of_part; ++i) {
if (text_rec[i]>0) {
if (text_rec[i]>0) { // TODO possible without conditional
text_rec[pos++] = text_rec[i];
}
}
Expand All @@ -392,23 +392,24 @@ void _construct_sa_se(int_vector_type& text, std::string filename_sa, uint64_t s
text_rec.resize(size_of_part);
util::_set_zero_bits(text_rec);
order = 0;
// TODO code duplication !!
for (size_t i=number_of_lms_strings-1; i<number_of_lms_strings; --i) {
if (!same_lms[i]) {
if (!same_lms[i]) { // TODO possible without conditional
++order;
}
if (left[i]/2 < size_of_part) {
if (left[i]/2 < size_of_part) { // TODO possible without conditional
text_rec[left[i]/2] = order;
}
}
pos = 0;
for (size_t i=0; i<size_of_part; ++i) {
if (text_rec[i]>0) {
if (text_rec[i]>0) { // TODO possible without conditional
text_rec[pos++] = text_rec[i];
}
}
text_rec.resize(number_of_lms_strings);
int_vector_buffer<> buf(filename_text_rec_part2, std::ios::in, 1024*1024);
for (size_t i=0; i<buf.size(); ++i) {
for (size_t i=0; i<buf.size(); ++i) { // TODO possible without conditional
text_rec[pos++] = buf[i];
}
buf.close(true);
Expand All @@ -418,13 +419,13 @@ void _construct_sa_se(int_vector_type& text, std::string filename_sa, uint64_t s
util::_set_zero_bits(text_rec);
order = 0;
for (size_t i=number_of_lms_strings-1; i<number_of_lms_strings; --i) {
if (!same_lms[i]) {
if (!same_lms[i]) { // TODO possible without conditional
++order;
}
text_rec[left[left_pointer--]/2] = order;
}
for (size_t i=0, pos=0; i<text_rec.size(); ++i) {
if (text_rec[i]>0) {
if (text_rec[i]>0) { // TODO possible without conditional
text_rec[pos++] = text_rec[i];
}
}
Expand Down
2 changes: 1 addition & 1 deletion include/sdsl/csa_alphabet_strategy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ class succinct_byte_alphabet
assert(1 == D[0]); // null-byte should occur exactly once
m_sigma = 0;
for (int i=0; i<256; ++i)
if (D[i]) {
if (D[i]) { // TODO possible without conditional
tmp_char[i] = 1; // mark occurring character
D[m_sigma] = D[i]; // compactify m_C
++m_sigma;
Expand Down
14 changes: 7 additions & 7 deletions include/sdsl/csa_sampling_strategy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class _sa_order_sampling : public int_vector<t_width>

for (size_type i=0, cnt_mod=sample_dens, cnt_sum=0; i < n; ++i, ++cnt_mod) {
size_type sa = sa_buf[i];
if (sample_dens == cnt_mod) {
if (sample_dens == cnt_mod) { // TODO possible without conditional
cnt_mod = 0;
(*this)[cnt_sum++] = sa;
}
Expand Down Expand Up @@ -151,7 +151,7 @@ class _text_order_sampling : public int_vector<t_width>

for (size_type i=0, sa_cnt=0; i < n; ++i) {
size_type sa = sa_buf[i];
if (0 == (sa % sample_dens)) {
if (0 == (sa % sample_dens)) { // TODO possible without conditional
marked[i] = 1;
(*this)[sa_cnt++] = sa;
}
Expand Down Expand Up @@ -299,18 +299,18 @@ class _bwt_sampling : public int_vector<t_width>
size_type sa = sa_buf[i];
char_type bwt = bwt_buf[i];
if (0 == (sa % sample_dens)) {
marked[i] = 1;
++sa_cnt;
marked[i] = 1; // TODO same as below
++sa_cnt; // TODO same as below
} else if (char_map.find(bwt) != char_map.end()) {
marked[i] = 1;
++sa_cnt;
marked[i] = 1; // TODO same as above
++sa_cnt; // TODO same as above
}
}
this->resize(sa_cnt);
sa_cnt = 0;
for (size_type i=0; i < n; ++i) {
size_type sa = sa_buf[i];
if (marked[i]) {
if (marked[i]) { // TODO possible without conditional
(*this)[sa_cnt++] = sa;
}
}
Expand Down
4 changes: 2 additions & 2 deletions include/sdsl/cst_sada.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ class cst_sada
util::set_to_value(m_bp, 0);
size_type idx=0;
for (cst_sct3<>::const_iterator it=temp_cst.begin(), end=temp_cst.end(); it!=end; ++it) {
if (1 == it.visit())
if (1 == it.visit()) // TODO possible without conditional
m_bp[idx] = 1;
if (temp_cst.is_leaf(*it) and temp_cst.root()!= *it)
if (temp_cst.is_leaf(*it) and temp_cst.root()!= *it) // TODO possible without conditional
++idx;
++idx;
}
Expand Down
4 changes: 2 additions & 2 deletions include/sdsl/dac_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ dac_vector<t_b, t_rank>::dac_vector(const Container& c)
t = sum_blocks;
sum_blocks += m_level_pointer_and_rank[i];
m_level_pointer_and_rank[i] = t;
if (sum_blocks > t) {
if (sum_blocks > t) { // TODO possible without conditional
++m_max_level;
last_block_size = sum_blocks - t;
}
Expand Down Expand Up @@ -311,7 +311,7 @@ dac_vector<t_b, t_rank>::dac_vector(int_vector_buffer<int_width>& v_buf)
t = sum_blocks;
sum_blocks += m_level_pointer_and_rank[i];
m_level_pointer_and_rank[i] = t;
if (sum_blocks > t) {
if (sum_blocks > t) { // TODO possible without conditional
++m_max_level;
last_block_size = sum_blocks - t;
}
Expand Down
8 changes: 4 additions & 4 deletions include/sdsl/enc_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ enc_vector<t_coder, t_dens,t_width>::enc_vector(const Container& c)
v2 = *it;
if (!no_sample) { // add a sample
no_sample = get_sample_dens();
if (max_sample_value < v2) max_sample_value = v2;
if (max_sample_value < v2) max_sample_value = v2; // TODO possible without conditional
++samples;
} else {
z_size += t_coder::encoding_length(v2-v1);
Expand All @@ -242,11 +242,11 @@ enc_vector<t_coder, t_dens,t_width>::enc_vector(const Container& c)
size_type no_sample=0;
for (it = c.begin(); it != end; ++it, --no_sample) {
v2 = *it;
if (!no_sample) { // add a sample
if (!no_sample) { // add a sample // TODO possible without conditional
no_sample = get_sample_dens();
*sv_it = v2; ++sv_it;
*sv_it = z_size; ++sv_it;
} else {
} else { // TODO possible without conditional
x = v2-v1;
z_size += t_coder::encoding_length(x);
}
Expand Down Expand Up @@ -289,7 +289,7 @@ enc_vector<t_coder, t_dens,t_width>::enc_vector(int_vector_buffer<int_width>& v_
v2 = v_buf[i];
if (!no_sample) { // is sample
no_sample = sd;
if (max_sample_value < v2) max_sample_value = v2;
if (max_sample_value < v2) max_sample_value = v2; // TODO possible without conditional
++samples;
} else {
z_size += t_coder::encoding_length(v2-v1);
Expand Down
4 changes: 2 additions & 2 deletions include/sdsl/fast_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ struct fast_cache {
// Returns true if the request i is cached and
// x is set to the answer of request i
bool exists(size_type i, size_type& x) {
if (m_table[(i&CACHE_SIZE)<<1 ] == i) {
if (m_table[(i&CACHE_SIZE)<<1 ] == i) { // TODO possible without conditional
x = m_table[((i&CACHE_SIZE)<<1) + 1 ];
return true;
} else
} else // TODO possible without conditional
return false;
}
// Writes the answer for request i to the cache
Expand Down
4 changes: 2 additions & 2 deletions include/sdsl/int_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ class int_vector
int_vector(std::initializer_list<t_T> il) : int_vector() {
resize(il.size());
size_type idx = 0;
for (auto x : il) {
for (auto x : il) {
(*this)[idx++] = x;
}
}
Expand Down Expand Up @@ -1113,7 +1113,7 @@ template<class t_bv>
inline typename std::enable_if<std::is_same<typename t_bv::index_category ,bv_tag>::value, std::ostream&>::type
operator<<(std::ostream& os, const t_bv& bv)
{
for (auto b : bv) {
for (auto b : bv) {
os << b;
}
return os;
Expand Down
4 changes: 2 additions & 2 deletions include/sdsl/inv_perm_support.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class inv_perm_support
back_pointer = j;
}
}
if (all_steps > t_s) {
if (all_steps > t_s) { // TODO possible without conditional
marked[i] = 1;
max_back_pointer = std::max(max_back_pointer, back_pointer);
}
Expand Down Expand Up @@ -125,7 +125,7 @@ class inv_perm_support
back_pointer = j;
}
}
if (all_steps > t_s) {
if (all_steps > t_s) { // TODO possible without conditional
m_back_pointer[m_rank_marked(i)] = back_pointer;
}
}
Expand Down
Loading