Skip to content

Commit

Permalink
[FIX] warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
eseiler committed Nov 11, 2021
1 parent 6faf0d3 commit 66ea712
Show file tree
Hide file tree
Showing 8 changed files with 368 additions and 311 deletions.
1 change: 1 addition & 0 deletions include/sdsl/cereal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <cereal/archives/xml.hpp>
#include <cereal/cereal.hpp>
#include <cereal/details/traits.hpp>
#include <cereal/types/array.hpp>
#include <cereal/types/memory.hpp>
#include <cereal/types/vector.hpp>
#endif
Expand Down
2 changes: 1 addition & 1 deletion include/sdsl/csa_sampling_strategy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ class _fuzzy_isa_sampling_support
{
structure_tree_node * child = structure_tree::add_child(v, name, util::class_name(*this));
size_type written_bytes = 0;
written_bytes += m_select_marked_sa.serialize(out, v, "select_marked_sa");
written_bytes += m_select_marked_sa.serialize(out, child, "select_marked_sa");
structure_tree::add_size(child, written_bytes);
return written_bytes;
}
Expand Down
2 changes: 1 addition & 1 deletion include/sdsl/int_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@ class int_vector_const_iterator : public int_vector_iterator_base<t_int_vector>
m_len = it.m_len;
}

int_vector_const_iterator & operator=(const int_vector_const_iterator&) = default;
int_vector_const_iterator & operator=(const int_vector_const_iterator &) = default;

const_reference operator*() const
{
Expand Down
92 changes: 44 additions & 48 deletions include/sdsl/rank_support_int.hpp
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
// Copyright (c) 2016, the SDSL Project Authors. All rights reserved.
// Please see the AUTHORS file for details. Use of this source code is governed
// by a BSD license that can be found in the LICENSE file.
/*! \file rank_support_int.hpp
\brief rank_support_int.hpp contains classes that support a sdsl::int_vector with constant time rank information.
Rank is defined as the number of occurrences of a value up to a given position.
\author Christopher Pockrandt
*/
/*!\file rank_support_int.hpp
* \brief rank_support_int.hpp contains classes that support a sdsl::int_vector with constant time rank information.
* Rank is defined as the number of occurrences of a value up to a given position.
* \author Christopher Pockrandt
*/
#ifndef INCLUDED_SDSL_RANK_SUPPORT_INT
#define INCLUDED_SDSL_RANK_SUPPORT_INT

/** \defgroup rank_support_group Rank Support (RS)
* This group contains data structures which support an sdsl::int_vector with the rank method.
*/

#include "int_vector.hpp"
#include "uint128_t.hpp"
#include <sdsl/int_vector.hpp>
#include <sdsl/uint128_t.hpp>

// TODO: benchmark the use of compiler hints for branch prediction
#define likely(x) __builtin_expect((x),1)
#define unlikely(x) __builtin_expect((x),0)
#define likely(x) __builtin_expect((x), 1)
#define unlikely(x) __builtin_expect((x), 0)

//! Namespace for the succinct data structure library.
namespace sdsl {
namespace sdsl
{

//! The base class of classes supporting rank_queries for a sdsl::int_vector in constant time.
/*!
*/

constexpr size_t floor_log2(size_t const n)
{
Expand All @@ -38,16 +37,16 @@ constexpr size_t ceil_log2(size_t const n)
}

template <uint8_t alphabet_size>
class rank_support_int {
class rank_support_int
{

public:
public:
typedef typename int_vector<>::size_type size_type;
typedef typename int_vector<>::value_type value_type;

static_assert(alphabet_size > 2, "Rank support is only implemented on int_vectors with an alphabet size of > 2.");

protected:

protected:
// Constructs a bit mask with the pattern w of a given length.
// It is concatenated until the length of the bitmask reaches max_length.
template <typename uintX_t>
Expand All @@ -63,42 +62,40 @@ class rank_support_int {
for (value_type v = 0; v < alphabet_size; ++v)
{
masks[v] = v;
for (uint8_t i = sigma_bits * 2; i < 64; i <<= 1)
masks[v] |= masks[v] << i;
for (uint8_t i = sigma_bits * 2; i < 64; i <<= 1) masks[v] |= masks[v] << i;
}

uint64_t tmp_carry = masks[1];
for (value_type v = 0; v < alphabet_size; ++v)
masks[v] |= tmp_carry << sigma_bits;
for (value_type v = 0; v < alphabet_size; ++v) masks[v] |= tmp_carry << sigma_bits;

return masks;
}

protected:
static constexpr uint8_t sigma{alphabet_size};
static constexpr uint8_t sigma_bits{ceil_log2(alphabet_size)};
static constexpr uint8_t bits_per_word{(64 / sigma_bits) * sigma_bits};
static constexpr uint64_t even_mask{bm_rec<uint64_t>(bits::lo_set[sigma_bits], sigma_bits * 2, 64)};
static constexpr uint64_t carry_select_mask{bm_rec<uint64_t>(1ULL << sigma_bits, sigma_bits * 2, 64)};
protected:
static constexpr uint8_t sigma{ alphabet_size };
static constexpr uint8_t sigma_bits{ ceil_log2(alphabet_size) };
static constexpr uint8_t bits_per_word{ (64 / sigma_bits) * sigma_bits };
static constexpr uint64_t even_mask{ bm_rec<uint64_t>(bits::lo_set[sigma_bits], sigma_bits * 2, 64) };
static constexpr uint64_t carry_select_mask{ bm_rec<uint64_t>(1ULL << sigma_bits, sigma_bits * 2, 64) };
static const std::array<uint64_t, alphabet_size> masks;

const int_vector<>* m_v; //!< Pointer to the rank supported bit_vector
const int_vector<> * m_v; //!< Pointer to the rank supported bit_vector

public:
public:
//! Constructor
/*! \param v The supported int_vector.
*/
rank_support_int(const int_vector<>* v = nullptr)
rank_support_int(const int_vector<> * v = nullptr)
{ // Check that the actual width of the vector has same size as sigma_bits.
assert((v != nullptr) ? sigma_bits == v->width() : true);
m_v = v;
}

//! Copy constructor
rank_support_int(const rank_support_int&) = default;
rank_support_int(rank_support_int&&) = default;
rank_support_int& operator=(const rank_support_int&) = default;
rank_support_int& operator=(rank_support_int&&) = default;
rank_support_int(const rank_support_int &) = default;
rank_support_int(rank_support_int &&) = default;
rank_support_int & operator=(const rank_support_int &) = default;
rank_support_int & operator=(rank_support_int &&) = default;
//! Destructor
virtual ~rank_support_int() {}

Expand All @@ -117,31 +114,30 @@ class rank_support_int {
//! Answers rank queries for the supported int_vector.
/*! \param i Argument for the length of the prefix v[0..i-1].
* \param v Argument which value (including smaller values) to count.
* \returns Number of occurrences of elements smaller or equal to v in the prefix [0..i-1] of the supported int_vector.
* \note Method init has to be called before the first call of rank.
* \sa init
* \returns Number of occurrences of elements smaller or equal to v in the prefix [0..i-1] of the supported
* int_vector. \note Method init has to be called before the first call of rank. \sa init
*/
virtual size_type prefix_rank(const size_type i, const value_type v) const = 0;

//! Serializes rank_support_int.
/*! \param out Out-Stream to serialize the data to.
*/
virtual size_type serialize(std::ostream& out, structure_tree_node* v, const std::string name) const = 0;
virtual size_type serialize(std::ostream & out, structure_tree_node * v, const std::string name) const = 0;

//! Loads the rank_support_int.
/*! \param in In-Stream to load the rank_support_int data from.
* \param v The supported int_vector.
*/
virtual void load(std::istream& in, const int_vector<>* v = nullptr) = 0;
virtual void load(std::istream & in, const int_vector<> * v = nullptr) = 0;

//! Sets the supported int_vector to the given pointer.
/*! \param v The new int_vector to support.
* \note Method init has to be called before the next call of rank or prefix_rank.
* \sa init, rank, prefix_rank
*/
virtual void set_vector(const int_vector<>* v = nullptr) = 0;
virtual void set_vector(const int_vector<> * v = nullptr) = 0;

protected:
protected:
// Mask the set prefix positions.
static constexpr uint64_t mask_prefix(value_type const v, uint64_t const w_even, uint64_t const w_odd) noexcept
{
Expand All @@ -156,7 +152,7 @@ class rank_support_int {
// Count how often value v or smaller occurs in the word w.
static constexpr uint64_t set_positions_prefix(const uint64_t w, const value_type v) noexcept
{
uint64_t const w_even = even_mask & w; // retrieve even positions
uint64_t const w_even = even_mask & w; // retrieve even positions
uint64_t const w_odd = even_mask & (w >> sigma_bits); // retrieve odd positions
return mask_prefix(v, w_even, w_odd);
}
Expand All @@ -167,25 +163,25 @@ class rank_support_int {
{
assert(v > 0);
// optimiyed version of set_positions(w, v) - set_positions(w, v - 1)
uint64_t const w_even = even_mask & w; // retrieve even positions
uint64_t const w_even = even_mask & w; // retrieve even positions
uint64_t const w_odd = even_mask & (w >> sigma_bits); // retrieve odd positions
uint64_t res = ((masks[v] - w_even) & ~(masks[v - 1] - w_even)) & carry_select_mask;
res |= (((masks[v] - w_odd) & ~(masks[v - 1] - w_odd)) & carry_select_mask) << 1;
return res;
}

// Counts the occurrences of elements smaller or equal to v in the word starting at data up to position idx.
template <typename ...value_t>
template <typename... value_t>
static constexpr std::array<uint64_t, sizeof...(value_t)> word_prefix_rank(const uint64_t word,
const size_type bit_pos,
const value_t ...values) noexcept
const value_t... values) noexcept
{
uint64_t const mask = bits::lo_set[(bit_pos % bits_per_word) + 1];

uint64_t const w_even = even_mask & word; // retrieve even positions
uint64_t const w_even = even_mask & word; // retrieve even positions
uint64_t const w_odd = even_mask & (word >> sigma_bits); // retrieve odd positions

return {(bits::cnt(mask_prefix(values, w_even, w_odd) & mask))...};
return { (bits::cnt(mask_prefix(values, w_even, w_odd) & mask))... };
}

// Counts the occurrences of elements smaller or equal to v in the word starting at data up to position idx.
Expand All @@ -211,7 +207,7 @@ class rank_support_int {
}

// Returns the word a the given word position.
static constexpr uint64_t extract_word(const uint64_t* data, const size_type word_position) noexcept
static constexpr uint64_t extract_word(const uint64_t * data, const size_type word_position) noexcept
{
return *(data + word_position);
}
Expand All @@ -222,7 +218,7 @@ const std::array<uint64_t, alphabet_size> rank_support_int<alphabet_size>::masks

} // end namespace sdsl

#include "rank_support_int_v.hpp"
#include "rank_support_int_scan.hpp"
#include "rank_support_int_v.hpp"

#endif // end file
79 changes: 45 additions & 34 deletions include/sdsl/rank_support_int_scan.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
// Copyright (c) 2016, the SDSL Project Authors. All rights reserved.
// Please see the AUTHORS file for details. Use of this source code is governed
// by a BSD license that can be found in the LICENSE file.
/*! \file rank_support_int_scan.hpp
\brief rank_support_int_scan.hpp contains rank_support_int_scan that support a sdsl::int_vector with linear time rank information.
\author Christopher Pockrandt
*/
/*!\file rank_support_int_scan.hpp
* \brief rank_support_int_scan.hpp contains rank_support_int_scan that support a sdsl::int_vector with linear time
* rank information.
* \author Christopher Pockrandt
*/
#ifndef INCLUDED_SDSL_RANK_SUPPORT_INT_SCAN
#define INCLUDED_SDSL_RANK_SUPPORT_INT_SCAN

#include "rank_support_int.hpp"
#include <sdsl/rank_support_int.hpp>

//! Namespace for the succinct data structure library.
namespace sdsl {
namespace sdsl
{

//! A class supporting rank queries in linear time.
/*! \par Space complexity
Expand All @@ -24,30 +26,37 @@ namespace sdsl {
*/

template <uint8_t alphabet_size>
class rank_support_int_scan : public rank_support_int<alphabet_size> {
private:
class rank_support_int_scan : public rank_support_int<alphabet_size>
{
private:
using base_t = rank_support_int<alphabet_size>;
public:

public:
typedef int_vector<> int_vector_type;
typedef typename rank_support_int<alphabet_size>::size_type size_type;
typedef typename rank_support_int<alphabet_size>::value_type value_type;

public:
explicit rank_support_int_scan(const int_vector<>* v = nullptr) : rank_support_int<alphabet_size>(v){};
rank_support_int_scan(const rank_support_int_scan& rs) = default;
rank_support_int_scan(rank_support_int_scan&& rs) = default;
rank_support_int_scan& operator=(const rank_support_int_scan& rs) = default;
rank_support_int_scan& operator=(rank_support_int_scan&& rs) = default;
public:
explicit rank_support_int_scan(const int_vector<> * v = nullptr)
: rank_support_int<alphabet_size>(v){};
rank_support_int_scan(const rank_support_int_scan & rs) = default;
rank_support_int_scan(rank_support_int_scan && rs) = default;
rank_support_int_scan & operator=(const rank_support_int_scan & rs) = default;
rank_support_int_scan & operator=(rank_support_int_scan && rs) = default;
size_type rank(size_type idx, const value_type v) const;
size_type operator()(size_type idx, const value_type v) const { return rank(idx, v); };
size_type prefix_rank(size_type idx, const value_type v) const;
size_type size() const { return this->m_v->size(); };
size_type serialize(std::ostream& out, structure_tree_node* v = nullptr, const std::string name = "") const
size_type serialize(std::ostream & out, structure_tree_node * v = nullptr, const std::string name = "") const
{
return serialize_empty_object(out, v, name, this);
}
void load(std::istream&, const int_vector<>* v = nullptr) { this->m_v = v; this->init(v); }
void set_vector(const int_vector<>* v = nullptr) { this->m_v = v; }
void load(std::istream &, const int_vector<> * v = nullptr)
{
this->m_v = v;
this->init(v);
}
void set_vector(const int_vector<> * v = nullptr) { this->m_v = v; }
};

//! Counts the occurrences of v in the prefix [0..idx-1]
Expand All @@ -56,21 +65,22 @@ class rank_support_int_scan : public rank_support_int<alphabet_size> {
* \sa prefix_rank
*/
template <uint8_t alphabet_size>
inline typename rank_support_int_scan<alphabet_size>::size_type
rank_support_int_scan<alphabet_size>::rank(const size_type idx, const value_type v) const
inline typename rank_support_int_scan<alphabet_size>::size_type rank_support_int_scan<alphabet_size>::rank(
const size_type idx,
const value_type v) const
{
assert(v < this->t_v);
assert(this->m_v != nullptr);
assert(idx <= this->m_v->size());

if (unlikely(v == 0))
return prefix_rank(idx, v);
if (unlikely(v == 0)) return prefix_rank(idx, v);

const uint64_t* p = this->m_v->data();
const uint64_t * p = this->m_v->data();
size_type i = 0;
size_type result = 0;
size_type word_pos = (idx * this->t_b) >> 6;
while (i < word_pos) {
while (i < word_pos)
{
result += base_t::full_word_rank(base_t::extract_word(p, i), v);
++i;
}
Expand All @@ -83,29 +93,30 @@ rank_support_int_scan<alphabet_size>::rank(const size_type idx, const value_type
* \sa rank
*/
template <uint8_t alphabet_size>
inline typename rank_support_int_scan<alphabet_size>::size_type
rank_support_int_scan<alphabet_size>::prefix_rank(const size_type idx, const value_type v) const
inline typename rank_support_int_scan<alphabet_size>::size_type rank_support_int_scan<alphabet_size>::prefix_rank(
const size_type idx,
const value_type v) const
{
assert(v < this->t_v);
assert(this->m_v != nullptr);
assert(idx <= this->m_v->size());

if (unlikely(v == this->t_v - 1))
return idx;
if (unlikely(v == this->t_v - 1)) return idx;

const uint64_t* p = this->m_v->data();
size_type word_pos = (idx * this->sigma_bits) >> 6;
size_type i = 0;
size_type result = 0;
const uint64_t * p = this->m_v->data();
size_type word_pos = (idx * this->sigma_bits) >> 6;
size_type i = 0;
size_type result = 0;

while (i < word_pos) {
while (i < word_pos)
{
result += base_t::full_word_prefix_rank(base_t::extract_word(p, i), v);
++i;
}

return result + base_t::word_prefix_rank(base_t::extract_word(p, idx), idx * this->sigma_bits, v)[0];
}

} // end namespace sds
} // namespace sdsl

#endif // end file
Loading

0 comments on commit 66ea712

Please sign in to comment.