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

various enhancements #421

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions examples/int-vector-buffer-iterator.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <sdsl/vectors.hpp>
#include <sdsl/int_vector_buffer.hpp>
#include <iostream>
#include <algorithm>

Expand Down
1 change: 1 addition & 0 deletions examples/uint64-array2int_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
#include <sdsl/util.hpp>
#include <sdsl/int_vector.hpp>
#include <sdsl/int_vector_buffer.hpp>
#include <iostream>
#include <string>

Expand Down
32 changes: 15 additions & 17 deletions include/sdsl/bits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
#ifndef INCLUDED_SDSL_BITS
#define INCLUDED_SDSL_BITS

#include <stdint.h> // for uint64_t uint32_t declaration
#include <iostream>// for cerr
#include <cassert>
#include <cstdint> // for uint64_t uint32_t declaration
#ifdef __BMI2__
#include <immintrin.h>
#endif
Expand Down Expand Up @@ -248,7 +246,7 @@ struct bits {
inline uint64_t bits::cnt(uint64_t x)
{
#ifdef __SSE4_2__
return __builtin_popcountll(x);
return static_cast<uint64_t>(__builtin_popcountll(x));
#else
#ifdef POPCOUNT_TL
return lt_cnt[x&0xFFULL] + lt_cnt[(x>>8)&0xFFULL] +
Expand Down Expand Up @@ -303,7 +301,7 @@ inline uint32_t bits::cnt11(uint64_t x)

inline uint32_t bits::cnt10(uint64_t x, uint64_t& c)
{
uint32_t res = cnt((x ^((x<<1) | c)) & (~x));
uint32_t res = static_cast<uint32_t>(cnt((x ^((x<<1) | c)) & (~x)));
c = (x >> 63);
return res;
}
Expand All @@ -315,7 +313,7 @@ inline uint64_t bits::map10(uint64_t x, uint64_t c)

inline uint32_t bits::cnt01(uint64_t x, uint64_t& c)
{
uint32_t res = cnt((x ^((x<<1) | c)) & x);
uint32_t res = static_cast<uint32_t>(cnt((x ^((x<<1) | c)) & x));
c = (x >> 63);
return res;
}
Expand All @@ -328,7 +326,7 @@ inline uint32_t bits::sel(uint64_t x, uint32_t i)
{
#ifdef __BMI2__
// index i is 1-based here, (i-1) changes it to 0-based
return __builtin_ctzll(_pdep_u64(1ull << (i-1), x));
return static_cast<uint32_t>(__builtin_ctzll(_pdep_u64(1ull << (i-1), x)));
#elif defined(__SSE4_2__)
uint64_t s = x, b;
s = s-((s>>1) & 0x5555555555555555ULL);
Expand All @@ -346,7 +344,7 @@ inline uint32_t bits::sel(uint64_t x, uint32_t i)
int byte_nr = __builtin_ctzll(b) >> 3; // byte nr in [0..7]
s <<= 8;
i -= (s >> (byte_nr<<3)) & 0xFFULL;
return (byte_nr << 3) + lt_sel[((i-1) << 8) + ((x>>(byte_nr<<3))&0xFFULL) ];
return (static_cast<unsigned int>(byte_nr) << 3) + lt_sel[((i-1) << 8) + ((x>>(byte_nr<<3))&0xFFULL) ];
#else
return _sel(x, i);
#endif
Expand Down Expand Up @@ -394,7 +392,7 @@ inline uint32_t bits::hi(uint64_t x)
#ifdef __SSE4_2__
if (x == 0)
return 0;
return 63 - __builtin_clzll(x);
return 63 - static_cast<uint32_t>(__builtin_clzll(x));
#else
uint64_t t,tt; // temporaries
if ((tt = x >> 32)) { // hi >= 32
Expand All @@ -420,7 +418,7 @@ inline uint32_t bits::lo(uint64_t x)
#ifdef __SSE4_2__
if (x==0)
return 0;
return __builtin_ctzll(x);
return static_cast<uint32_t>(__builtin_ctzll(x));
#else
if (x&1) return 0;
if (x&3) return 1;
Expand Down Expand Up @@ -548,23 +546,23 @@ inline uint64_t bits::read_unary_and_move(const uint64_t*& word, uint8_t& offset
{
uint64_t w = (*word) >> offset; // temporary variable is good for the performance
if (w) {
uint8_t r = bits::lo(w);
uint8_t r = static_cast<uint8_t>(bits::lo(w));
offset = (offset + r+1)&0x3F;
// we know that offset + r +1 <= 64, so if the new offset equals 0 increase word
word += (offset==0);
return r;
} else {
uint8_t rr=0;
if (0!=(w=*(++word))) {
rr = bits::lo(w)+64-offset;
rr = static_cast<uint8_t>(bits::lo(w)+64-offset);
offset = (offset+rr+1)&0x3F;
word += (offset==0);
return rr;
} else {
uint64_t cnt_1=1;
while (0==(w=*(++word)))
++cnt_1;
rr = bits::lo(w)+64-offset;
rr = static_cast<uint8_t>(bits::lo(w)+64-offset);
offset = (offset+rr+1)&0x3F;
word += (offset==0);
return ((cnt_1)<<6) + rr;
Expand Down Expand Up @@ -593,9 +591,9 @@ inline uint64_t bits::next(const uint64_t* word, uint64_t idx)
{
word += (idx>>6);
if (*word & ~lo_set[idx&0x3F]) {
return (idx & ~((size_t)0x3F)) + lo(*word & ~lo_set[idx&0x3F]);
return (idx & ~(static_cast<uint64_t>(0x3F))) + lo(*word & ~lo_set[idx&0x3F]);
}
idx = (idx & ~((size_t)0x3F)) + 64;
idx = (idx & ~(static_cast<uint64_t>(0x3F))) + 64;
++word;
while (*word==0) {
idx += 64;
Expand All @@ -608,9 +606,9 @@ inline uint64_t bits::prev(const uint64_t* word, uint64_t idx)
{
word += (idx>>6);
if (*word & lo_set[(idx&0x3F)+1]) {
return (idx & ~((size_t)0x3F)) + hi(*word & lo_set[(idx&0x3F)+1]);
return (idx & ~(static_cast<uint64_t>(0x3F))) + hi(*word & lo_set[(idx&0x3F)+1]);
}
idx = (idx & ~((size_t)0x3F)) - 64;
idx = (idx & ~(static_cast<uint64_t>(0x3F))) - 64;
--word;
while (*word==0) {
idx -= 64;
Expand Down
2 changes: 1 addition & 1 deletion include/sdsl/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace sdsl
namespace conf // namespace for library constant
{
// size of the buffer for reading and writing data in elements (not in bytes)
const uint64_t SDSL_BLOCK_SIZE = (uint64_t)1<<22;
const uint64_t SDSL_BLOCK_SIZE = static_cast<uint64_t>(1)<<22;

const char KEY_BWT[] = "bwt";
const char KEY_BWT_INT[] = "bwt_int";
Expand Down
5 changes: 3 additions & 2 deletions include/sdsl/construct.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "sdsl_concepts.hpp"
#include "int_vector.hpp"
#include "int_vector_buffer.hpp"
#include "construct_lcp.hpp"
#include "construct_bwt.hpp"
#include "construct_sa.hpp"
Expand Down Expand Up @@ -53,7 +54,7 @@ void append_zero_symbol(int_vector& text)


template<class t_index>
void construct(t_index& idx, std::string file, uint8_t num_bytes=0)
void construct(t_index& idx, const std::string& file, uint8_t num_bytes=0)
{
tMSS file_map;
cache_config config;
Expand All @@ -64,7 +65,7 @@ void construct(t_index& idx, std::string file, uint8_t num_bytes=0)
}

template<class t_index, class t_data>
void construct_im(t_index& idx, t_data data, uint8_t num_bytes=0)
void construct_im(t_index& idx, const t_data& data, uint8_t num_bytes=0)
{
std::string tmp_file = ram_file_name(util::to_string(util::pid())+"_"+util::to_string(util::id()));
store_to_file(data, tmp_file);
Expand Down
1 change: 1 addition & 0 deletions include/sdsl/construct_bwt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#define INCLUDED_SDSL_CONSTRUCT_BWT

#include "int_vector.hpp"
#include "int_vector_buffer.hpp"
#include "sfstream.hpp"
#include "util.hpp"
#include "config.hpp" // for cache_config
Expand Down
1 change: 1 addition & 0 deletions include/sdsl/construct_lcp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "config.hpp"
#include "int_vector.hpp"
#include "int_vector_buffer.hpp"
#include "sfstream.hpp"
#include "rank_support.hpp"
#include "select_support.hpp"
Expand Down
1 change: 1 addition & 0 deletions include/sdsl/construct_sa_se.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "io.hpp"
#include "int_vector.hpp"
#include "int_vector_buffer.hpp"
#include "rank_support.hpp"
#include "select_support.hpp"
#include <cmath>
Expand Down
1 change: 1 addition & 0 deletions include/sdsl/csa_alphabet_strategy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
*/

#include "int_vector.hpp"
#include "int_vector_buffer.hpp"
#include "sd_vector.hpp"
#include "rank_support.hpp"
#include "select_support.hpp"
Expand Down
1 change: 1 addition & 0 deletions include/sdsl/csa_bitcompressed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#define INCLUDED_SDSL_CSA_UNCOMPRESSED

#include "int_vector.hpp"
#include "int_vector_buffer.hpp"
#include "sdsl_concepts.hpp"
#include "suffix_array_helper.hpp"
#include "iterators.hpp"
Expand Down
1 change: 1 addition & 0 deletions include/sdsl/csa_sada.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "enc_vector.hpp"
#include "int_vector.hpp"
#include "int_vector_buffer.hpp"
#include "iterators.hpp"
#include "suffix_array_helper.hpp"
#include "util.hpp"
Expand Down
2 changes: 2 additions & 0 deletions include/sdsl/csa_sampling_strategy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@
*/

#include "int_vector.hpp"
#include "int_vector_buffer.hpp"
#include "csa_alphabet_strategy.hpp" // for key_trait
#include "inv_perm_support.hpp"
#include "wavelet_trees.hpp"
#include "construct.hpp"
#include <set>
#include <tuple>

Expand Down
1 change: 1 addition & 0 deletions include/sdsl/csa_wt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#define INCLUDED_SDSL_CSA_WT

#include "wavelet_trees.hpp"
#include "int_vector_buffer.hpp"
#include "suffix_array_helper.hpp"
#include "iterators.hpp"
#include "util.hpp"
Expand Down
1 change: 1 addition & 0 deletions include/sdsl/cst_sada.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#define INCLUDED_SDSL_CST_SADA

#include "int_vector.hpp"
#include "int_vector_buffer.hpp"
#include "iterators.hpp"
#include "lcp_support_sada.hpp"
#include "select_support_mcl.hpp"
Expand Down
1 change: 1 addition & 0 deletions include/sdsl/cst_sct3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#define INCLUDED_SDSL_CST_SCT3

#include "int_vector.hpp"
#include "int_vector_buffer.hpp"
#include "iterators.hpp"
#include "lcp.hpp"
#include "bp_support.hpp"
Expand Down
1 change: 1 addition & 0 deletions include/sdsl/dac_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "bits.hpp"
#include "int_vector.hpp"
#include "int_vector_buffer.hpp"
#include "iterators.hpp"
#include "rank_support_v5.hpp"
#include "rrr_vector.hpp"
Expand Down
1 change: 1 addition & 0 deletions include/sdsl/enc_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#define SDSL_ENC_VECTOR

#include "int_vector.hpp"
#include "int_vector_buffer.hpp"
#include "coder.hpp"
#include "iterators.hpp"

Expand Down
Loading