diff --git a/3party/succinct/bit_vector.hpp b/3party/succinct/bit_vector.hpp index 2f8bc4ab8e..5ca0e7db96 100644 --- a/3party/succinct/bit_vector.hpp +++ b/3party/succinct/bit_vector.hpp @@ -236,7 +236,7 @@ namespace succinct { other.m_bits.swap(m_bits); } - inline size_t size() const { + inline uint64_t size() const { return m_size; } @@ -277,12 +277,14 @@ namespace succinct { } // unsafe and fast version of get_word, it retrieves at least 56 bits + /* inline uint64_t get_word56(uint64_t pos) const { // XXX check endianness? const char* ptr = reinterpret_cast(m_bits.data()); return *(reinterpret_cast(ptr + pos / 8)) >> (pos % 8); } + */ inline uint64_t predecessor0(uint64_t pos) const { assert(pos < m_size); @@ -355,7 +357,7 @@ namespace succinct { , m_pos(uint64_t(-1)) {} - enumerator(bit_vector const& bv, size_t pos) + enumerator(bit_vector const& bv, uint64_t pos) : m_bv(&bv) , m_pos(pos) , m_buf(0) @@ -374,7 +376,7 @@ namespace succinct { return b; } - inline uint64_t take(size_t l) + inline uint64_t take(uint64_t l) { if (m_avail < l) fill_buf(); uint64_t val; @@ -422,9 +424,9 @@ namespace succinct { } bit_vector const* m_bv; - size_t m_pos; + uint64_t m_pos; uint64_t m_buf; - size_t m_avail; + uint64_t m_avail; }; struct unary_enumerator { @@ -504,7 +506,7 @@ namespace succinct { }; protected: - size_t m_size; + uint64_t m_size; mapper::mappable_vector m_bits; }; diff --git a/3party/succinct/darray.hpp b/3party/succinct/darray.hpp index f098c2e811..79920f2f8d 100644 --- a/3party/succinct/darray.hpp +++ b/3party/succinct/darray.hpp @@ -24,8 +24,8 @@ namespace succinct { std::vector subblock_inventory; std::vector overflow_positions; - for (size_t word_idx = 0; word_idx < data.size(); ++word_idx) { - size_t cur_pos = word_idx * 64; + for (uint64_t word_idx = 0; word_idx < data.size(); ++word_idx) { + uint64_t cur_pos = word_idx * 64; uint64_t cur_word = WordGetter()(data, word_idx); unsigned long l; while (broadword::lsb(cur_word, l)) { @@ -81,20 +81,20 @@ namespace succinct { return m_overflow_positions[overflow_pos + (idx % block_size)]; } - size_t subblock = idx / subblock_size; - size_t start_pos = uint64_t(block_pos) + m_subblock_inventory[subblock]; - size_t reminder = idx % subblock_size; + uint64_t subblock = idx / subblock_size; + uint64_t start_pos = uint64_t(block_pos) + m_subblock_inventory[subblock]; + uint64_t reminder = idx % subblock_size; mapper::mappable_vector const& data = bv.data(); if (!reminder) { return start_pos; } else { - size_t word_idx = start_pos / 64; - size_t word_shift = start_pos % 64; + uint64_t word_idx = start_pos / 64; + uint64_t word_shift = start_pos % 64; uint64_t word = WordGetter()(data, word_idx) & (uint64_t(-1) << word_shift); while (true) { - size_t popcnt = broadword::popcount(word); + uint64_t popcnt = broadword::popcount(word); if (reminder < popcnt) break; reminder -= popcnt; word = WordGetter()(data, ++word_idx); @@ -136,7 +136,7 @@ namespace succinct { static const size_t subblock_size = 32; static const size_t max_in_block_distance = 1 << 16; - size_t m_positions; + uint64_t m_positions; mapper::mappable_vector m_block_inventory; mapper::mappable_vector m_subblock_inventory; mapper::mappable_vector m_overflow_positions; diff --git a/3party/succinct/darray64.hpp b/3party/succinct/darray64.hpp index fdd4c3104b..07fad2bd9d 100644 --- a/3party/succinct/darray64.hpp +++ b/3party/succinct/darray64.hpp @@ -12,7 +12,7 @@ namespace succinct { : n_ones(0) {} - void append1(size_t skip0 = 0) + void append1(uint64_t skip0 = 0) { bits.append_bits(0, skip0); bits.push_back(1); @@ -27,7 +27,7 @@ namespace succinct { n_ones += 1; } - size_t n_ones; + uint64_t n_ones; bit_vector_builder bits; std::vector block_inventory; std::vector subblock_inventory; @@ -63,7 +63,7 @@ namespace succinct { ; } - size_t num_ones() const + uint64_t num_ones() const { return m_num_ones; } @@ -73,25 +73,25 @@ namespace succinct { return m_bits; } - size_t select(size_t idx) const + uint64_t select(uint64_t idx) const { assert(idx < num_ones()); - size_t block = idx / block_size; - size_t block_pos = m_block_inventory[block]; + uint64_t block = idx / block_size; + uint64_t block_pos = m_block_inventory[block]; - size_t subblock = idx / subblock_size; - size_t start_pos = block_pos + m_subblock_inventory[subblock]; - size_t reminder = idx % subblock_size; + uint64_t subblock = idx / subblock_size; + uint64_t start_pos = block_pos + m_subblock_inventory[subblock]; + uint64_t reminder = idx % subblock_size; if (!reminder) { return start_pos; } else { - size_t word_idx = start_pos / 64; - size_t word_shift = start_pos % 64; + uint64_t word_idx = start_pos / 64; + uint64_t word_shift = start_pos % 64; uint64_t word = m_bits.data()[word_idx] & (uint64_t(-1) << word_shift); while (true) { - size_t popcnt = broadword::popcount(word); + uint64_t popcnt = broadword::popcount(word); if (reminder < popcnt) break; reminder -= popcnt; word = m_bits.data()[++word_idx]; @@ -106,7 +106,7 @@ namespace succinct { static const size_t block_size = 1024; // 64 * block_size must fit in an uint16_t (64 is the max sparsity of bits) static const size_t subblock_size = 64; - size_t m_num_ones; + uint64_t m_num_ones; bit_vector m_bits; mapper::mappable_vector m_block_inventory; mapper::mappable_vector m_subblock_inventory; diff --git a/3party/succinct/gamma_vector.hpp b/3party/succinct/gamma_vector.hpp index 9da81149b8..7b31a249d2 100644 --- a/3party/succinct/gamma_vector.hpp +++ b/3party/succinct/gamma_vector.hpp @@ -38,14 +38,14 @@ namespace succinct { bit_vector(&low_bits).swap(m_low_bits); } - value_type operator[](size_t idx) const + value_type operator[](uint64_t idx) const { - size_t pos = m_high_bits.select(idx); - size_t l; // ignored + uint64_t pos = m_high_bits.select(idx); + uint64_t l; // ignored return retrieve_value(idx, pos, l); } - size_t size() const + uint64_t size() const { return m_high_bits.num_ones() - 1; } @@ -66,7 +66,7 @@ namespace succinct { private: - value_type retrieve_value(size_t idx, size_t pos, size_t& l) const + value_type retrieve_value(uint64_t idx, uint64_t pos, uint64_t & l) const { assert(m_high_bits.bits()[pos] == 1); l = broadword::lsb(m_high_bits.bits().get_word(pos + 1)); @@ -110,8 +110,8 @@ namespace succinct { private: gamma_vector const* m_c; - size_t m_idx; - size_t m_pos; + uint64_t m_idx; + uint64_t m_pos; bit_vector::unary_enumerator m_high_bits_enumerator; bit_vector::enumerator m_low_bits_enumerator; diff --git a/3party/succinct/mapper.hpp b/3party/succinct/mapper.hpp index 381e1992ef..b8c84fb645 100644 --- a/3party/succinct/mapper.hpp +++ b/3party/succinct/mapper.hpp @@ -11,8 +11,12 @@ #include "mappable_vector.hpp" + namespace succinct { namespace mapper { + #define NEED_TO_ALIGN4(v) (4 - ((v) % 4)) + #define ALIGN4_PTR(v) { uint32_t x = (uint64_t)(v) % 4; if (x > 0) (v) += 4 - x; } + struct freeze_flags { // enum { // }; @@ -34,7 +38,7 @@ namespace succinct { namespace mapper { {} std::string name; - size_t size; + uint64_t size; std::vector children; void dump(std::ostream& os = std::cerr, size_t depth = 0) { @@ -72,6 +76,14 @@ namespace succinct { namespace mapper { operator()(T& val, const char* /* friendly_name */) { m_fout.write(reinterpret_cast(&val), sizeof(T)); m_written += sizeof(T); + + uint32_t padding = NEED_TO_ALIGN4(m_written); + static uint32_t const zero = 0; + if (padding > 0 && padding < 4) + { + m_fout.write(reinterpret_cast(&zero), padding); + m_written += padding; + } return *this; } @@ -84,6 +96,14 @@ namespace succinct { namespace mapper { m_fout.write(reinterpret_cast(vec.m_data), long(n_bytes)); m_written += n_bytes; + uint32_t padding = NEED_TO_ALIGN4(m_written); + static uint32_t const zero = 0; + if (padding > 0 && padding < 4) + { + m_fout.write(reinterpret_cast(&zero), padding); + m_written += padding; + } + return *this; } @@ -120,6 +140,8 @@ namespace succinct { namespace mapper { operator()(T& val, const char* /* friendly_name */) { val = *reinterpret_cast(m_cur); m_cur += sizeof(T); + + ALIGN4_PTR(m_cur); return *this; } @@ -141,6 +163,7 @@ namespace succinct { namespace mapper { } m_cur += bytes; + ALIGN4_PTR(m_cur); return *this; } @@ -168,7 +191,7 @@ namespace succinct { namespace mapper { template typename boost::disable_if, sizeof_visitor&>::type operator()(T& val, const char* friendly_name) { - size_t checkpoint = m_size; + uint64_t checkpoint = m_size; size_node_ptr parent_node; if (m_cur_size_node) { parent_node = m_cur_size_node; @@ -195,9 +218,9 @@ namespace succinct { namespace mapper { template sizeof_visitor& operator()(mappable_vector& vec, const char* friendly_name) { - size_t checkpoint = m_size; + uint64_t checkpoint = m_size; (*this)(vec.m_size, "size"); - m_size += static_cast(vec.m_size * sizeof(T)); + m_size += static_cast(vec.m_size * sizeof(T)); if (m_cur_size_node) { make_node(friendly_name)->size = m_size - checkpoint; @@ -206,7 +229,7 @@ namespace succinct { namespace mapper { return *this; } - size_t size() const { + uint64_t size() const { return m_size; } @@ -225,7 +248,7 @@ namespace succinct { namespace mapper { return node; } - size_t m_size; + uint64_t m_size; size_node_ptr m_cur_size_node; }; @@ -261,7 +284,7 @@ namespace succinct { namespace mapper { } template - size_t size_of(T& val) + uint64_t size_of(T& val) { detail::sizeof_visitor sizer; sizer(val, "");